#include <iostream>
#include <string.h>
using namespace std;
struct Trie{
Trie* next[26];
int num;
Trie()
{
int i;
for(i=0;i<26;i++){
next[i] = NULL;
}
num=0;
}
};
Trie root;
void Insert(char word[])
{
Trie *p = &root;
int i;
for(i=0;word[i];i++){
if(p->next[word[i]-'a']==NULL)
p->next[word[i]-'a'] = new Trie;
p = p->next[word[i]-'a'];
p->num++;
}
}
int Find(char word[])
{
Trie *p = &root;
int i;
for(i=0;word[i];i++){
if(p->next[word[i]-'a']==NULL)
return 0;
p = p->next[word[i]-'a'];
}
return p->num;
}
int main()
{
char word[11];
while(cin.getline(word,12)){
if(strlen(word)==0 || word[0]==' ')
break;
Insert(word);
}
while(scanf("%s",word)!=EOF){
printf("%d\n",Find(word));
}
return 0;
}