#include <bits/stdc++.h>
using namespace std;
const int N = 1e5-20;
int n;
int TOT=0;
namespace AC {
int tr[N][130], tot;set<int> ans;
int fail[N],end[N];
void insert(char *s,int id) {
int u = 0;
for (int i = 1; s[i]; i++) {
if (!tr[u][s[i]]) tr[u][s[i]] = ++tot;
u = tr[u][s[i]];
}
end[u]=id;
// v[u].push_back(id);
}
queue<int> q;
void build() {
for (int i = 0; i < 129; i++)
if (tr[0][i]) q.push(tr[0][i]);
while (q.size()) {
int u = q.front();
q.pop();
for (int i = 0; i < 129; i++) {
if (tr[u][i])
fail[tr[u][i]] = tr[fail[u]][i], q.push(tr[u][i]);
else
tr[u][i] = tr[fail[u]][i];
}
}
}
int query(char *t,int id) {
int u = 0, res = 0;ans.clear();
for (int i = 1; t[i]; i++) {
u = tr[u][t[i]]; // 转移
for (int j = u; j ; j = fail[j]) {
if(end[j]) ans.insert(end[j]);
}
}
if(ans.size()){
printf("web %d:",id);TOT++;
for(auto it:ans){printf(" %d",(it));}
printf("\n");
}
return res;
}
void init(){
memset(end,0,sizeof end);
memset(fail,0,sizeof fail);
memset(tr,0,sizeof tr);
tot=0;
}
} // namespace AC
char s[N];int T,m;
int main() {
T=1;
while(T--){
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", s + 1), AC::insert(s,i);
AC::build();
scanf("%d",&m);
for(int i=1;i<=m;i++){
scanf("%s", s + 1);
AC::query(s,i);
}
printf("total: %d\n",TOT);
// printf("%d\n", );
// return 0;
}
}
09-16
636
09-10
169