#include<stdio.h>
#include<stack>
#define l 10005
using namespace std;
int a[l],b[l];
stack<int>st;
int main()
{
int t,n,i,f,j;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&n);
while(n--)
{
for(j=1;j<=t;j++)
{
scanf("%d",&b[j]);
}
i=1;j=1;f=1;
while(j<=t)
{
if(a[i]==b[j])
{
i++;
j++;
}
else if(!st.empty()&&st.top()==b[j])
{
st.pop();
j++;
}
else if(i<=t)
{
st.push(a[i++]);
}
else
{
f=0;
break;
}
}
if(f==1)
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
return 0;
}
#include<stack>
#define l 10005
using namespace std;
int a[l],b[l];
stack<int>st;
int main()
{
int t,n,i,f,j;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&n);
while(n--)
{
for(j=1;j<=t;j++)
{
scanf("%d",&b[j]);
}
i=1;j=1;f=1;
while(j<=t)
{
if(a[i]==b[j])
{
i++;
j++;
}
else if(!st.empty()&&st.top()==b[j])
{
st.pop();
j++;
}
else if(i<=t)
{
st.push(a[i++]);
}
else
{
f=0;
break;
}
}
if(f==1)
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
return 0;
}