#include <bits/stdc++.h>
#define ll long long
using namespace std;
int calc_hash(const string &s, int off, int len) {
int r=0;
for(int i=off;i<off+len;i++){
char c=s[i];
if(c=='A')c=1;
else if(c=='T')c=2;
else if(c=='G')c=3;
else c=4;
r=r*5+c;
}
return r;
}
int v[10000000];
int main () {
string s;
cin>>s;
int n;
cin>>n;
for (int i = 1; i <= min(10, (int)s.length()); i++) {
for (int j = 0; j <= s.length() - i; j++) {
v[calc_hash(s, j, i)] = 1;
}
}
for (int i = 0; i < n; i++) {
string x;
cin>>x;
if (v[calc_hash(x,0,x.length())]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}