#include<iostream> #include<string> using namespace std; struct TreeNode{ int data; TreeNode* lchild; TreeNode* rchild; TreeNode(int n):data(n),lchild(NULL),rchild(NULL){} }; TreeNode* Insert(TreeNode* root,int x){ if(root==NULL){ root=new TreeNode(x); } else if(x>root->data){ root->rchild=Insert(root->rchild,x); } else{ root->lchild=Insert(root->lchild,x); } return root; } bool Compare(TreeNode* root1,TreeNode* root2){ if(root1==NULL&&root2==NULL){ return true; } if(root1==NULL||root2==NULL||root1->data!=root2->data){ return false; } return Compare(root1->lchild,root2->lchild)&&Compare(root1->rchild,root2->rchild); } int main(){ int n; while(cin>>n){ if(n==0){ break; } string s; cin>>s; TreeNode* root1=NULL; for(int i=0;i<s.size();i++){ int x=s[i]-'0'; root1=Insert(root1,x); } while(n){ string a; cin>>a; int t; TreeNode* root2=NULL; for(int i=0;i<s.size();i++){ t=a[i]-'0'; root2=Insert(root2,t); } if(Compare(root1,root2)){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } n--; } } }