#include<iostream>#include<string>#include<vector>#include<cctype>#include<cstdio>#include<cstring>#include<algorithm>#include<unordered_map>#include<cmath>#include<cctype>usingnamespace std;constint N =1e6+5;int son[N][26], cnt[N], idx =0;voidinsert(string &word){int p =0;for(int i =0; i < word.size(); i++){int u = word[i]-'a';if(son[p][u]==0) son[p][u]=++idx;
p = son[p][u];
cnt[p]++;}}intquery(string &word){int p =0;for(int i =0; i < word.size(); i++){int u = word[i]-'a';if(son[p][u]==0)return0;
p = son[p][u];}return cnt[p];}intmain(){int n, m;
cin>>n;
string str;while(n--){
cin>>str;insert(str);}
cin>>m;while(m--){
cin>>str;
cout<<query(str)<<endl;;}return0;}