#include <iostream>//建树,使用前序遍历,判断前序遍历结果是否相同
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

//       5               5                 5
//     4   6          4     6         3          7
//   3        7     3          7    2   4      6
// 2              2
typedef struct Node {
    char c;
    Node* l;
    Node* r;
} TN;

TN* Buiid(TN* root, char c) {
    if (root == NULL) {
        root = new TN();
        root->c = c;
    }
    else if (c < root->c)root->l = Buiid(root->l, c);
    else if (c > root->c)root->r = Buiid(root->r, c);
    return root;
}

string ans1 = ""; //存放前序遍历结果
void preOrder(TN* root) {
    if (root == NULL)return;
    ans1 = ans1 + root->c;
//  cout<<root->c<<" ";
    preOrder(root->l);
    preOrder(root->r);
}


int main() {
    int n;
    string s;

    while (cin >> n && n) {
        cin >> s;
        TN* tree = NULL;
        for (int i = 0; i < s.size(); i++) {
            tree = Buiid(tree, s[i]);
        }
        preOrder(tree);
        string ans = ans1;
        for (int i = 0; i < n; i++) {
            string tre;
            ans1 = "";
            cin >> tre;
            TN* tree1 = NULL;
            for(int i=0;i<tre.size();i++)
            {
                tree1 = Buiid(tree1,tre[i]);
            }
            preOrder(tree1);
            string ans2 = ans1;
            if(ans1==ans)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }

}
// 64 位输出请用 printf("%lld")