#include <bits/stdc++.h>
using namespace std;

int conv(char c) {
    return (int)c;
}

class Trie {
    public:
        Trie *next[256], *del[256], *suff, *dictSuff;
        int ind;
        Trie();
        ~Trie();
        void destroy();
        Trie *step(int ch);
};

Trie::Trie(): suff(NULL), ind(-1), dictSuff(NULL) {
    for (int i=0; i<256; i++) {
        next[i]=NULL;
        del[i]=NULL;
    }
}

Trie::~Trie() {
}

void Trie::destroy() {
    for (int i=0; i<256; i++) if (this->del[i]) this->del[i]->destroy();
    delete this;
}

Trie *Trie::step(int ch) {
    if (this->next[ch]) {
        return this->next[ch];
    }
    else if (this->suff) {
        return this->next[ch]=this->suff->step(ch);
    }
    else return this;
}

void addDict(Trie *t, vector<string>& v2) {
    vector<pair<string,int> > v;
    for (int i=0; i<(int)v2.size(); i++) {
        v.push_back(make_pair(v2[i],i));
    }
    sort(v.begin(),v.end(),[](const pair<string,int>& a, const pair<string,int>& b)->bool {
            return a.first.length()<b.first.length();
            });
    vector<Trie*> tnode(v.size(),t);
    int j=0;
    for (int i=0; j<v.size(); i++) {
        for (int k=j; k<v.size(); k++) {
            int ch=conv(v[k].first[i]);
            if (!tnode[k]->next[ch]) {
                tnode[k]->next[ch]=new Trie();
                tnode[k]->del[ch]=tnode[k]->next[ch];
            }
            Trie *nd=tnode[k];
            bool chng=(nd->next[ch]->suff==NULL);
            if (chng) nd->next[ch]->suff=nd->suff;
            nd=nd->next[ch];
            if (chng) {
                while (nd->suff && !nd->suff->next[ch]) {
                    nd->suff=nd->suff->suff;
                }
                if (nd->suff) {
                    nd->suff=nd->suff->next[ch];
                }
                else {
                    nd->suff=t;
                }
                nd->dictSuff=nd->suff;
                while (nd->dictSuff && nd->dictSuff->ind==-1) {
                    nd->dictSuff=nd->dictSuff->dictSuff;
                }
                if (!nd->dictSuff) {
                    nd->dictSuff=t;
                }
            }
            tnode[k]=nd;
        }
        while (j<v.size() && i+1==v[j].first.length()) {
            tnode[j]->ind=v[j].second;
            j++;
        }
    }
}

int main(void) {
    string s, ex;
    int n;
    vector<string> v;
    vector<bool> good;
    Trie *t=new Trie();
    cin >> s >> n;
    for (int i=0; i<n; i++) {
        cin >> ex;
        v.push_back(ex);
        good.push_back(false);
    }
    addDict(t,v);
    Trie *now=t;
    for (int i=0; i<s.length(); i++) {
        now=now->step(conv(s[i]));
        if (now->ind!=-1) {
            Trie *ex=now;
            while (ex && ex->ind!=-1) {
                good[ex->ind]=true;
                ex=ex->dictSuff;
            }
        }
    }
    for (int i=0; i<n; i++) cout << (good[i]? 'Y': 'N') << "\n";
    t->destroy();
    return 0;
}
