1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 using namespace std;
5 int n,m;
6 struct node{
7 node *next[26];
8 }*root;
9 node *create(){
10 node *p=new(node);
11 memset(p,0,sizeof(p->next));
12 return p;
13 }
14 char s[10];
15 void insert(char *w){
16 node *p=root;// 取根节点
17 char *q=w;// 该单词的指针
18 while(*q){// 单词没有到头
19 int k=*q-'a';
20 if(p->next[k]==NULL)
21 p->next[k]=create();// 这个字符没有 -- 新建
22 p=p->next[k];// p向下指
23 q++;// 单词指针后移一位
24 }
25 }
26 bool Judge(char *w){
27 node *p=root;char *q=w;
28 int now=0;
29 while(*q){
30 int id=*q-'a';
31 if(p->next[id]==NULL) return false;
32 else { q++;p=p->next[id]; }
33 }
34 return true;
35 }
36 int main()
37 {
38 scanf("%d",&n);
39 root=create();// 先建造根节点
40 for(int i=1;i<=n;i++){
41 scanf("%s",s);
42 insert(s);
43 }
44 scanf("%d",&m);
45 for(int i=1;i<=m;i++){
46 scanf("%s",s);
47 if(Judge(s)) printf("YES\n");
48 else printf("NO\n");
49 }
50 return 0;
51 }