WA on 2 3 4。
/****************************************
作者:
版权:
日期:
*****************************************/
#include<bits/stdc++.h>
using namespace std;
const int N = 5e6 + 1;
int cnt, ans[N], ToT, n, Q;
struct TRIE {
int ch[71],ans;
} t[N];
int gc(char c) {
if (isupper(c)) {
return c - 'A';
}
if (islower(c)) {
return c - 'a' + 26;
}
if (isdigit(c)) {
return c - '0' + 52;
}
}
void insert(string s) {
int root = 0;
// t[root].init();
for (auto v : s) {
int y = gc(v);
if (t[root].ch[y] == 0) {
t[root].ch[y] = ++cnt;
// t[cnt].init();
root = cnt;
} else root = t[root].ch[y];
t[root].ans++;
}
}
int found(string s) { //寻找前缀
int root = 0;
for (auto v : s) {
int y = gc(v);
if (t[root].ch[y] == 0) {
return 0;
}
// ++ans;
// cout<<root<<'\n';
root=t[root].ch[y];
// cout<<root<<'\n';
}
// cout<<"add\n";
return t[root].ans;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> ToT;
while (ToT--) {
cin >> n >> Q;
cnt=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=61;j++){
t[i].ch[j]=0;
}
t[i].ans=0;
}
for (int i = 1; i <= n; i++) {
string ppt;
cin >> ppt;
insert(ppt);
}
// ans=0;
while (Q--) {
string ppt;
cin >> ppt;
cout<<found(ppt)<<'\n';
}
}
return 0;
}