# include <stdio.h>
# include <algorithm>
# include <string>
# include <map>
# include <iostream>
using namespace std;
int main()
{
char a;
string x;
map<string,int>q;
while(true)
{
scanf("%c",&a);
if(a=='\n')
{
scanf("%c",&a);
x="";//一个结束x初始化
}
if(a=='\n')//连续两个\n结束了母串的输入
break;
x+=a;
q[x]+=1;
}
while(cin>>x)
printf("%d\n",q[x]);
return 0;
}