#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
map<string,vector<int> > student;
// vector<string> all;
int n,k;
scanf("%d%d",&n,&k);
int i;
for(i=0;i<k;i++)
{
int index,num;
scanf("%d %d",&index,&num);
for(int j=0;j<num;j++)
{
vector<int> tmp;
// string name;
char name[5];
scanf("%s",name);
tmp=student[name];
tmp.push_back(index);
student[name]=tmp;
}
}
for(i=0;i<n;i++)
{
vector<int> tmp;
// string name;
char name[5];
scanf("%s",name);
tmp=student[name];
sort(tmp.begin(),tmp.end());
int size=tmp.size();
cout<<name<<" "<<size;
for(int j=0;j<size;j++)
cout<<" "<<tmp[j];
cout<<endl;
}
return 0;
}
#include<map>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
map<string,vector<int> > student;
// vector<string> all;
int n,k;
scanf("%d%d",&n,&k);
int i;
for(i=0;i<k;i++)
{
int index,num;
scanf("%d %d",&index,&num);
for(int j=0;j<num;j++)
{
vector<int> tmp;
// string name;
char name[5];
scanf("%s",name);
tmp=student[name];
tmp.push_back(index);
student[name]=tmp;
}
}
for(i=0;i<n;i++)
{
vector<int> tmp;
// string name;
char name[5];
scanf("%s",name);
tmp=student[name];
sort(tmp.begin(),tmp.end());
int size=tmp.size();
cout<<name<<" "<<size;
for(int j=0;j<size;j++)
cout<<" "<<tmp[j];
cout<<endl;
}
return 0;
}