#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();
}