importjava.io.*;importjava.util.*;publicclassMain{staticintN,M;staticint[][]subjects=newint[1001][];staticboolean[][]students=newboolean[10001][51];staticvoidsolution(){for(inti=0;i<M;i++){intcnt=0;for(intj=0;j<N;j++){intNN=subjects[j].length;booleanpass=true;for(intk=0;k<NN;k++){inttime=subjects[j][k];// 과목 수업 시간에 학생이 비는 시간이 아니면if(!students[i][time]){pass=false;break;}}if(pass)cnt++;}System.out.println(cnt);}}publicstaticvoidmain(String[]args)throwsException{BufferedReaderin=newBufferedReader(newInputStreamReader(System.in));N=Integer.parseInt(in.readLine());for(inti=0;i<N;i++){StringTokenizerst=newStringTokenizer(in.readLine()," ");intNN=Integer.parseInt(st.nextToken());// 과목의 수업 시간 저장subjects[i]=newint[NN];for(intj=0;j<NN;j++)subjects[i][j]=Integer.parseInt(st.nextToken());}M=Integer.parseInt(in.readLine());for(inti=0;i<M;i++){StringTokenizerst=newStringTokenizer(in.readLine()," ");intMM=Integer.parseInt(st.nextToken());// 학생의 비는 시간 저장for(intj=0;j<MM;j++){inttime=Integer.parseInt(st.nextToken());students[i][time]=true;}}solution();}}