# include <iostream># include<stdio.h># include<string.h># include<stdlib.h># include<math.h># include<algorithm># include<map># include<vector>using namespace std;struct str{ char a[205][35]; int x;}s[105];char ch[105][35];int num[105];char str1[3505];map<string, int> mapp;struct str2{ char aa[35];}ss[205];bool cmp(str2 x1, str2 y1){ return strcmp(x1.aa, y1.aa) < 0;}int main(){ int n; while(~scanf("%d", &n)) { for(int i = 0; i < n; i ++) { scanf("%s", ch[i]); getchar(); gets(str1); int len = strlen(str1); char chch[35]; memset(chch, ' ', sizeof(chch)); int l = 0; for(int j = 0, k = 0; j <= len; j ++) { if(str1[j] != ' ' && str1[j] != ' ') chch[k ++] = str1[j]; else { strcpy(s[i].a[l ++], chch); memset(chch, ' ', sizeof(chch)); k = 0; } } s[i].x = l; } int m; scanf("%d", &m); getchar(); for(int i = 0; i < m; i ++) { mapp.clear(); gets(str1); int len = strlen(str1); char chch[35]; memset(chch, ' ', sizeof(chch)); int l = 0, count = 0, ii = 0; for(int j = 0; j <= len; j ++) { if(str1[j] != ' ' && str1[j] != ' ') chch[l ++] = str1[j]; else { count ++; for(int kk = 0; kk < n; kk ++) { if(strcmp(chch, ch[kk]) == 0) { num[ii ++] = kk; break; } } memset(chch, ' ', sizeof(chch)); l = 0; } } for(int i = 0; i < count; i ++) { for(int j = 0; j < s[num[i]].x; j ++) { mapp[s[num[i]].a[j]] ++; } } int k = 0; for(int i = 0; i < s[num[0]].x ; i ++) { if(mapp[s[num[0]].a[i]] == count) { strcpy(ss[k ++].aa,s[num[0]].a[i]); } } if(k == 0) printf("NOn"); else { sort(ss,ss + k, cmp); int f = 0; for(int i = 0; i < k; i ++) { if(f == 1) { printf(" "); } printf("%s", ss[i].aa); f = 1; } printf("n"); } } } return 0;}


