include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int a[100],b[100],n,m,i,j,sum=0;
scanf("%d",&n);
for(i=0;i<7;i++)
{
scanf("%d",&a[i]);
}
while(n--)
{
for(j=0;j<7;j++)
{ scanf("%d",&b[j]);}
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(a[i]=b[j])
sum++;
}
}
printf("%d",sum);sum=0;
}
return 0;
}