#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
class CA
{
public:
void run();
map<string,vector<string> > qm[5];
int n,m;
};
void CA::run()
{
cin>>n;
while(n-->0)
{
string id,title,author,wordslist,publisher,year;
cin>>id;getchar();
getline(cin,title);
getline(cin,author);
getline(cin,wordslist);
getline(cin,publisher);
cin>>year;
qm[0][title].push_back(id);
qm[1][author].push_back(id);
qm[3][publisher].push_back(id);
qm[4][year].push_back(id);
istringstream istr(wordslist);
while(!istr.eof())
{
string keyword;
istr>>keyword;
qm[2][keyword].push_back(id);
}
}
int i;
for(i=0;i<5;i++)
{
map<string,vector<string> >::iterator imp;
for(imp=qm[i].begin();imp!=qm[i].end();imp++)
{
sort(imp->second.begin(),imp->second.end());
}
}
cin>>m;
while(m-->0)
{
int no;
string scon;
cin>>no;getchar();getchar();
getline(cin,scon);
cout<<no<<": "<<scon<<endl;
vector<string>::iterator ivstr;
map<string,vector<string> >::iterator imp;
imp=qm[no-1].find(scon);
if(imp!=qm[no-1].end())
{
for(ivstr=qm[no-1][scon].begin();ivstr!=qm[no-1][scon].end();ivstr++)
{
cout<<*ivstr<<endl;
}
}
else
{
cout<<"Not Found"<<endl;
}
}
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}