#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n,Root;
int inorder[N],postorder[N];
int l[N],r[N],father[N];
unordered_map<int,int> pos;
int Level[N];
int build(int li,int ri,int lp,int rp)
{
if(li > ri) return 0;
int root = postorder[rp];
int k = pos[root];
l[root] = build(li,k-1,lp,lp+k-1-li);//左子树
if(l[root] != 0) father[l[root]] = root;
r[root] = build(k+1,ri,lp+k-li,rp-1);//右子树
if(r[root] != 0) father[r[root]] = root;
return root;
}
void get_level(int root,int level)
{
if(root == 0) return;
Level[root] = level;
get_level(l[root],level+1);
get_level(r[root],level+1);
}
bool is_full(int root)
{
if((r[root] == 0) && (l[root] == 0))//叶子节点
return true;
if((r[root] == 0)^(l[root] == 0))//度为1的节点
return false;
return is_full(l[root]) && is_full(r[root]);
}
bool solve(const string& str)
{
int A,B;
if(str.find("root") < str.size())
{
sscanf(str.c_str(),"%d",&A);
return A == Root;
}
else if(str.find("siblings") < str.size())
{
sscanf(str.c_str(),"%d and %d",&A,&B);
if(A == B) return false;
return father[A] == father[B];
}
else if(str.find("parent") < str.size())
{
sscanf(str.c_str(),"%d is the parent of %d",&A,&B);
return l[A] == B || r[A] == B;
}
else if(str.find("left") < str.size())
{
sscanf(str.c_str(),"%d is the left child of %d",&A,&B);
return l[B] == A;
}
else if(str.find("right") < str.size())
{
sscanf(str.c_str(), "%d is the right child of %d", &A, &B);
return r[B] == A;
}
else if(str.find("same level") < str.size())
{
sscanf(str.c_str(),"%d and %d",&A,&B);
return Level[A] == Level[B];
}
else if(str.find("full tree") < str.size())
{
return is_full(Root);
}
}
int main()
{
cin>>n;
for(int i = 0; i<n; i++) cin>>postorder[i];
for(int i = 0; i<n; i++)
{
cin>>inorder[i];
pos[inorder[i]] = i;
}
Root = build(0,n-1,0,n-1);
get_level(Root,1);
int m;
cin>>m;
getchar();
string str;
while(m--)
{
getline(cin,str);
if(solve(str)) puts("Yes");
else puts("No");
}
return 0;
}