#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> ans[11];
int n;
void Load()
{
cin >> s;
n = s.length();
}
int Encode(string &s, int l, int r) {
int ans = 0;
for (int i = l; i < r; i++) {
ans *= 4;
if (s[i] == 'A') ans += 0;
if (s[i] == 'T') ans += 1;
if (s[i] == 'G') ans += 2;
if (s[i] == 'C') ans += 3;
}
return ans;
}
void Solve() {
int i, j;
for (i = 1; i <= 10; i++) {
ans[i].resize(1 << (2*i));
for (j = 0; j < n - i; j++) {
ans[i][Encode(s, j, j+i)] = 1;
}
}
cin >> j;
for (i = 0; i < j; i++) {
string ss;
cin >> ss;
int k = ss.length();
if (ans[k][Encode(ss, 0, k)])
cout << "YES\n";
else
cout << "NO\n";
}
}
int main(){
Load();
Solve();
return 0;
}