#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
//DFA 求字符串最多匹配多少字符串
const int maxn=2000000;
struct Node
{
int num;//出现次数
int index;//序号
Node *next[128];//后继指针
Node* fail;//失败指针
/*指向树中出现过的S的最长的后缀,换句话说就是在前缀集中出现的最长的S的后缀.*/
};
//字典树
Node temp[maxn];
int tp;
//.........
int n;//字符串个数
Node *root;//头指针
void reset(Node* rot)
{
rot->num=0;
for(int i=0;i<128;i++) rot->next[i]=NULL;
rot->fail=root;//important
if(rot==root) rot->fail=NULL;//important
}
//初始化
void init()
{
tp=0;
root=&temp[tp++];
reset(root);
}
//插入字典树
void insert(char *word,int index)
{
Node *p=root;
for(int i=0;word[i];i++)
{
int x=word[i];
if(p->next[x]==NULL)
{
p->next[x]=&temp[tp++];
reset(p->next[x]);
}
p=p->next[x];
}
p->num=index;
}
//构造失败指针
Node *que[maxn];
int front,rear;
void DFA()
{
Node* p=root;
front=rear=0;
que[rear++]=p;
while(front<rear)
{
Node* t=que[front++];
for(int i=0;i<128;i++)
{
Node* cnt=t->next[i];
if(cnt!=NULL)
{
Node* fath=t->fail;
while(fath!=NULL&&fath->next[i]==NULL)
{
fath=fath->fail;
}
if(fath!=NULL)
{
cnt->fail=fath->next[i];
}
else
{
cnt->fail=p;//important
}
que[rear++]=cnt;
}
}
}
}
int mat[3000];
int l;
//查看str最多匹配多少字符串
void find(char* str)
{
Node* p=root;
Node* fath;
Node* cnt;
for(int i=0;str[i];i++)
{
int x=str[i];
cnt=p->next[x];
if(cnt!=NULL)
{
for(fath=cnt;fath!=NULL;fath=fath->fail)
{
if(fath->num)
{
mat[l++]=fath->num;
}
}
p=cnt;
}
else
{
fath=p->fail;
while(fath!=NULL&&fath->next[x]==NULL)
{
fath=fath->fail;
}
if(fath!=NULL)
{
cnt=fath->next[x];
for(fath=cnt;fath!=NULL;fath=fath->fail)
{
if(fath->num)
{
mat[l++]=fath->num;
}
}
p=cnt;
}
else
{
p=root;
}
}
}
}
char str[1000005];
int main()
{
while(scanf("%d ",&n)==1)//important 空格
{
init();//初始化
for(int i=0;i<n;i++)
{
gets(str);
insert(str,i+1);//在字典树上插入字符串
}
DFA();//构造失败指针
int m;scanf("%d",&m);
int cnt=0;
for(int i=1;i<=m;i++)
{
l=0;
scanf("%s",str);
find(str);
sort(mat,mat+l);
l=unique(mat,mat+l)-mat;
if(l)
{
cnt++;
printf("web %d:",i);
for(int j=0;j<l;j++) printf(" %d",mat[j]);
printf("/n");
}
}
printf("total: %d/n",cnt);
}
return 0;
}