#include <bits/stdc++.h>
using namespace std;
struct Node{
char c;
Node *left;
Node *right;
};
Node *insert(Node *root,char c)
{
if(root==NULL)
{
root=new Node();
root->c=c;
}
else if(c>root->c){
root->left=insert(root->left,c);
}
else if(c<root->c){
root->right=insert(root->right,c);
}
return root;
}
bool is_equal(Node *root1,Node *root2)
{
if(root1==NULL&&root2==NULL) return true;
else if((root1!=NULL&&root2==NULL)||(root2!=NULL&&root1==NULL)) return false;
//else return(root1->c==root2->c);//错在这里,根节点不为空,值不同可以判断两树不同,但根值相同不能说树相同
else if(root1->c!=root2->c) return false;
return is_equal(root1->left,root2->left)&&is_equal(root1->right,root2->right);
}
int main(){
int n;
while(cin>>n)
{
if(n==0) break;
string s1;
cin>>s1;
Node *root1=NULL;
for(int i=0;i<s1.size();i++)
{
root1=insert(root1,s1[i]);
}
for(int i=0;i<n;i++)
{
string s2;
Node *root2=NULL;
cin>>s2;
for(int j=0;j<s2.size();j++)
{
root2=insert(root2,s2[j]);
}
if(is_equal(root1,root2)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
return 0;
}