#include <bits/stdc++.h>
using namespace std;
const int p = 261, mod = 1e9+7, N = 100010;
string str;
int n, arr[N], p_pow[N];
void cal_arr() {
p_pow[0] = 1;
for(int i=0, curr=0; i<n; i++) {
curr += 1LL*p_pow[i]*(str[i]-'0'+1)%mod;
p_pow[i+1] = 1LL*p_pow[i]*p%mod;
if(curr>=mod)
curr -= mod;
arr[i] = curr;
}
}
int get_hash(string str) {
int hash = 0;
for(int i=0; i<(int)str.length(); i++) {
hash += 1LL*p_pow[i]*(str[i]-'0'+1)%mod;
if(hash>=mod)
hash -= mod;
}
return hash;
}
bool check(int x, int k) {
int hash = 0;
for(int i=k-1; i<n; i++) {
hash = arr[i] - (i>=k ? arr[i-k] : 0);
if(hash<0)
hash += mod;
if(hash==x)
return 1;
x = 1LL*p*x%mod;
}
return 0;
}
void solve() {
cin >> str;
n = str.length();
cal_arr();
int k;
cin >> k;
string t;
while(k--) {
cin >> t;
cout << ( check(get_hash(t), t.length()) ? 'Y' : 'N' ) << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//int _t; cin >> _t; while(_t--)
solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgcCA9IDI2MSwgbW9kID0gMWU5KzcsIE4gPSAxMDAwMTA7CnN0cmluZyBzdHI7CmludCBuLCBhcnJbTl0sIHBfcG93W05dOwoKdm9pZCBjYWxfYXJyKCkgewogICAgcF9wb3dbMF0gPSAxOwogICAgZm9yKGludCBpPTAsIGN1cnI9MDsgaTxuOyBpKyspIHsKICAgICAgICBjdXJyICs9IDFMTCpwX3Bvd1tpXSooc3RyW2ldLScwJysxKSVtb2Q7CiAgICAgICAgcF9wb3dbaSsxXSA9IDFMTCpwX3Bvd1tpXSpwJW1vZDsKICAgICAgICBpZihjdXJyPj1tb2QpCiAgICAgICAgICAgIGN1cnIgLT0gbW9kOwogICAgICAgIGFycltpXSA9IGN1cnI7CiAgICB9Cn0KCmludCBnZXRfaGFzaChzdHJpbmcgc3RyKSB7CiAgICBpbnQgaGFzaCA9IDA7CiAgICBmb3IoaW50IGk9MDsgaTwoaW50KXN0ci5sZW5ndGgoKTsgaSsrKSB7CiAgICAgICAgaGFzaCArPSAxTEwqcF9wb3dbaV0qKHN0cltpXS0nMCcrMSklbW9kOwogICAgICAgIGlmKGhhc2g+PW1vZCkKICAgICAgICAgICAgaGFzaCAtPSBtb2Q7CiAgICB9CiAgICByZXR1cm4gaGFzaDsKfQoKYm9vbCBjaGVjayhpbnQgeCwgaW50IGspIHsKICAgIGludCBoYXNoID0gMDsKICAgIGZvcihpbnQgaT1rLTE7IGk8bjsgaSsrKSB7CiAgICAgICAgaGFzaCA9IGFycltpXSAtIChpPj1rID8gYXJyW2kta10gOiAwKTsKICAgICAgICBpZihoYXNoPDApCiAgICAgICAgICAgIGhhc2ggKz0gbW9kOwogICAgICAgIGlmKGhhc2g9PXgpCiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHggPSAxTEwqcCp4JW1vZDsKICAgIH0KICAgIHJldHVybiAwOwp9Cgp2b2lkIHNvbHZlKCkgewogICAgY2luID4+IHN0cjsKICAgIG4gPSBzdHIubGVuZ3RoKCk7CiAgICBjYWxfYXJyKCk7CiAgICBpbnQgazsKICAgIGNpbiA+PiBrOwogICAgc3RyaW5nIHQ7CiAgICB3aGlsZShrLS0pIHsKICAgICAgICBjaW4gPj4gdDsKICAgICAgICBjb3V0IDw8ICggY2hlY2soZ2V0X2hhc2godCksIHQubGVuZ3RoKCkpID8gJ1knIDogJ04nICkgPDwgJ1xuJzsKICAgIH0KfQoKc2lnbmVkIG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKCiAgICAjaWZuZGVmIE9OTElORV9KVURHRQogICAgICAgIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oIm91dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICAjZW5kaWYKCiAgICAvL2ludCBfdDsgY2luID4+IF90OyB3aGlsZShfdC0tKQogICAgc29sdmUoKTsKfQ==