#include <cstddef> #include <iostream> #include <cstring> using namespace std; struct BStree{ int data; BStree* lchild; BStree* rchild; BStree(int x):data(x),lchild(NULL),rchild(NULL){} }; BStree* buildBS(BStree* r,int x){ if(r==NULL){ r=new BStree(x); } else if(x<r->data){ r->lchild=buildBS(r->lchild, x); } else r->rchild=buildBS(r->rchild, x); return r; } bool mjudge(BStree* a,BStree* b){ if(a==NULL && b== NULL) return true; else if(a->data==b->data) return true&&mjudge(a->lchild, b->lchild) &&mjudge(a->rchild, b->rchild); else return false; } BStree* string2bs(string x){ BStree* r=NULL; for(int i=0;i<x.length() ;i++){ r=buildBS(r,x[i]-'0'); } return r; } int main() { int n; while(cin>>n){ if(n==0) break; string o; cin>>o; BStree* root1=string2bs(o); for(int i=0;i<n;i++){ string news; cin>>news; BStree* root2=string2bs(news); if(mjudge(root1,root2)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } }