#include <bits/stdc++.h>
using namespace std;
class TrieTree_Node { //Tire树结点
public:
bool flag;
TrieTree_Node *node[26]{};
TrieTree_Node() {
flag = false;
memset(node, 0, sizeof node);
}
} root;
void Inster(string s) { //字符串插入Trie树
TrieTree_Node *p = &root;
for (int i = 0; i < s.length(); i++) {
int index = s[i] - 'a'; //把小写字母a~z映射到数字的1~26,作为字典树的每一层的索引
if (!p->node[index])
p->node[index] = new TrieTree_Node;
p = p->node[index];
}
p->flag = true;
}
bool Find(string t) { //寻找字符串是否出现过
TrieTree_Node *p = &root;
for (int i = 0; i < t.length(); i++) {
int index = t[i] - 'a'; //把小写字母a~z映射到数字的1~26,作为字典树的每一层的索引
if (!p->node[index])
return false;
p = p->node[index];
}
return p->flag;
}
int main() {
int n, m;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
Inster(s);
}
cin >> m;
for (int i = 0; i < m; i++) {
string t;
cin >> t;
if (Find(t))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
/*
Input:
5
apple
app
balance
cat
dog
5
balance
appl
app
apple
dog
Output:
Yes
No
Yes
Yes
Yes
*/