using namespace std;
struct tree
{
tree * lson;
tree * rson;
int value;
};
tree * head;
tree * exa;
void build( tree * tmp,int cc){
if(tmp->value>cc){
if(tmp->lson!=NULL)build(tmp->lson,cc);
else{
tree * tt=new tree();tt->lson=NULL;tt->rson=NULL;
tt->value=cc;
tmp->lson=tt;
}
}
else if(tmp->value<cc){
if(tmp->rson!=NULL)build(tmp->rson,cc);
else{
tree * tt=new tree();tt->lson=NULL;tt->rson=NULL;
tt->value=cc;
tmp->rson=tt;
}
}
}
void preorder(tree * tt){
cout<<tt->value<<" ";
if(tt->lson!=NULL)preorder(tt->lson);
if(tt->rson!=NULL)preorder(tt->rson);
}
void midorder(tree * tt){
if(tt->lson!=NULL)midorder(tt->lson);
cout<<tt->value<<" ";
if(tt->rson!=NULL)midorder(tt->rson);
}
void aftorder(tree * tt){
if(tt->lson!=NULL)aftorder(tt->lson);
if(tt->rson!=NULL)aftorder(tt->rson);
cout<<tt->value<<" ";
}
bool treecmp(tree * a,tree * b){
if(a==NULL&&b==NULL)return 1;
else if(a!=NULL && b!= NULL && a->value == b->value) {
if(treecmp(a->lson,b->lson)&&treecmp(a->rson,b->rson))return 1;
else return 0;
} else return 0;
}
int main()
{
int n;cin>>n;
while(n!=0){
int l,tt,tmp;cin>>l;
cin>>tt;
head=new tree();head->lson=NULL;head->rson=NULL;head->value=tt;
for(int i=1;i<n;i++){
cin>>tt;
build(head,tt);
}
preorder(head);puts("");
midorder(head);puts("");
aftorder(head);puts("");
puts("-------------------");*/
while(l--){
exa=new tree();
cin>>tt;
exa->lson=NULL;exa->rson=NULL;exa->value=tt;
for(int i=1;i<n;i++){
cin>>tt;
build(exa,tt);
}
if(treecmp(head,exa))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
preorder(exa);puts("");
midorder(exa);puts("");
aftorder(exa);puts("");
puts("-------------------");*/
}
cin>>n;
}
return 0;
}