#include <iostream>
#include <cstdio>
#include<limits>
#include <map>
#include <cstring>
#include <string>
using namespace std;
const int N =100005;
struct tree
{
int num;
tree *next[26];
tree()
{
num=0;
for(int i=0; i<26; i++)
{
next[i]=NULL;
}
}
} t;
void In(char str[])
{
tree *p = &t;
int cnt;
for(int i = 0; str[i]; i++)
{
cnt = str[i]-'a';
if(p->next[cnt]==NULL)
{
p->next[cnt] = new tree();
}
p->next[cnt]->num++;
p=p->next[cnt];
}
}
int Find(char str[])
{
tree *p = &t;
int cnt, i;
for(i=0; str[i]; i++)
{
cnt = str[i] - 'a';
if(p->next[cnt]==NULL)
{
return 0;
}
else
{
p = p->next[cnt];
}
}
return p->num;
}
int main()
{
int n, scan;
char str[N];
scanf("%d", &scan);
while(scan--)
{
scanf("%s", str);
In(str);
}
scanf("%d", &n);
while(n--)
{
scanf("%s", str);
printf("%d\n", Find(str));
}
return 0;
}
#include <cstdio>
#include<limits>
#include <map>
#include <cstring>
#include <string>
using namespace std;
const int N =100005;
struct tree
{
int num;
tree *next[26];
tree()
{
num=0;
for(int i=0; i<26; i++)
{
next[i]=NULL;
}
}
} t;
void In(char str[])
{
tree *p = &t;
int cnt;
for(int i = 0; str[i]; i++)
{
cnt = str[i]-'a';
if(p->next[cnt]==NULL)
{
p->next[cnt] = new tree();
}
p->next[cnt]->num++;
p=p->next[cnt];
}
}
int Find(char str[])
{
tree *p = &t;
int cnt, i;
for(i=0; str[i]; i++)
{
cnt = str[i] - 'a';
if(p->next[cnt]==NULL)
{
return 0;
}
else
{
p = p->next[cnt];
}
}
return p->num;
}
int main()
{
int n, scan;
char str[N];
scanf("%d", &scan);
while(scan--)
{
scanf("%s", str);
In(str);
}
scanf("%d", &n);
while(n--)
{
scanf("%s", str);
printf("%d\n", Find(str));
}
return 0;
}