#include <stdio.h>
#include <string.h>
int num[10005], a[10005], p = 0, q = 0;
int main()
{
int n, i, j, k, m, t;
scanf("%d", &n);
for(i = 0; i < n; i++)scanf("%d", &num[i]);
scanf("%d", &t);
while(t--)
{
p = q = 0;
for(k = 0; k < n; k++)
{
scanf("%d", &m);
if(p == 0)
{
a[p++] = num[q++];
while(q < n && a[p - 1] != m)
{
a[p++] = num[q++];
}
if(a[p - 1] == m)p--;
}
else
{
if(a[p - 1] != m)
{
while(q < n && a[p - 1] != m)
{
a[p++] = num[q++];
}
if(a[p - 1] == m)p--;
}
else p--;
}
}
if(p == 0)printf("yes\n");
else printf("no\n");
}
return 0;
}