#include<iostream>
#include<cstdio>
#define L 11
using namespace std;
typedef struct Node{
int num;
struct Node *child[26];
Node(){
num = 0;
int i;
for(i=0;i<26;i++){
child[i] = NULL;
}
}
}Node;
void InTree(Node *root, char word[]){
for(int i=0;word[i];i++){
int pos = word[i]-'a';
if(root->child[pos] == NULL)
root->child[pos] = new Node();
root->child[pos]->num++;
root = root->child[pos];
}
}
int findTree(Node* root, char word[]){
for(int i=0;word[i];i++){
int pos = word[i]-'a';
if(root->child[pos] == NULL)
return 0;
root = root->child[pos];
}
return root->num;
}
int main()
{
int n,m;
char dic[L];
char w[L];
Node *tnode = new Node();
cin>>n;
for(int i=0;i<n;i++){
cin>>dic;
InTree(tnode, dic);
}
cin>>m;
for(int i=0;i<m;i++){
cin>>w;
cout<<findTree(tnode, w)<<endl;
}
return 0;
}