#include <iostream>
#include <cstdio>
using namespace std;
const int N = 110;
string text[N];
int n,m;
string str;
int ans[N];
int main()
{
cin >> n >> m;
getchar();
for(int i=0;i < n;i++) getline(cin,text[i]) ; // 有空格可能读不进去 的读法 可以了!// 读了一个空行进去
// for(int i=0;i < n;i++) cout << text[i] << endl;
int tmp = m;
while(tmp--)
{
getline(cin,str);
// 判断输入的类型 标签 id 后代
int num = 0,j = 0;
for(int i=0;i < n;i++)
{
if(text[i].find(str) != -1)
{
num++,ans[j] = i + 1,j++;
}
}
cout << num << " ";
for(int k=0;k < j;k++)
{
cout << ans[k] << " ";
}
cout << endl;
}
return 0;
}
/*
11 5
html
..head
....title
..body
....h1
....p #subtitle
....div #main
......h2
......p #one
......div
........p #two
p
#subtitle
h3
div p
div div p
*/
06-09
337
