#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define mii map<int,int>
#define uii unordered_map<int,int>
#define si set<int>
#define usi set<int>
#define pb push_back
#define mp make_pair
int32_t main(){
string s;
cin >> s;
int n = s.size();
int p = 31;
vector<int> p_pow(n+1,1);
vector<int> hash(n+1,0);
for(int i=1;i<=n;i++)
p_pow[i] = (p_pow[i-1] * p)%mod;
for(int i=1;i<=n;i++){
int v;
if(s[i-1] >= 'A' && s[i-1] <= 'Z'){
v = s[i-1] - 'A' + 1;
}else{
v = s[i-1] - 'a' + 1;
}
hash[i] = (hash[i-1] + (v) * p_pow[i-1])%mod;
}
int q;
cin >> q;
while(q--){
string m;
cin >> m;
int a_hash = 0;
for(int i=0;i<m.size();i++){
int v;
if(m[i] >= 'A' && m[i] <= 'Z'){
v = m[i] - 'A' + 1;
}else{
v = m[i] - 'a' + 1;
}
a_hash = (a_hash + (v) * p_pow[i])%mod;
}
bool flag = true;
for(int i=1;i<=(n-m.size()+1);i++){
int curr_hash = (hash[i+m.size()-1] - hash[i-1] + mod)%mod;
if(curr_hash == (a_hash * p_pow[i-1])%mod){
cout << "Y\n";
flag = false;
break;
}
}
if(flag) cout << "N\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKI2RlZmluZSBpbnQgbG9uZyBsb25nCiNkZWZpbmUgcGlpIHBhaXI8aW50LGludD4KI2RlZmluZSBtaWkgbWFwPGludCxpbnQ+CiNkZWZpbmUgdWlpIHVub3JkZXJlZF9tYXA8aW50LGludD4KI2RlZmluZSBzaSBzZXQ8aW50PgojZGVmaW5lIHVzaSBzZXQ8aW50PgojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgppbnQzMl90IG1haW4oKXsKCXN0cmluZyBzOwoJY2luID4+IHM7CglpbnQgbiA9IHMuc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