#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = (10000)+10;
int tr[maxn];
int n;
int a, b;
int xid, yid;
void build(int rt, int val){
if(tr[rt] == -1) tr[rt] = val;
else if(val<tr[rt]) build(rt<<1, val);
else build(rt<<1|1, val);
return ;
}
bool judge1(){
for(int i=1; i<maxn; i++){
if(tr[i] == a){
xid = i;
break;
}
}
if(xid!=1) return false;
return true;
}
bool judge2(){
for(int i=1; i<maxn; i++){
if(tr[i] == a){
xid = i;
}
if(tr[i] == b){
yid = i;
}
}
if(xid/2!=yid/2) return false;
return true;
}
bool judge3(){
for(int i=1; i<maxn; i++){
if(tr[i] == a){
xid = i;
}
if(tr[i] == b){
yid = i;
}
}
if(xid !=yid/2) return false;
return true;
}
bool judge4(){
for(int i=1; i<maxn; i++){
if(tr[i] == a){
xid = i;
}
if(tr[i] == b){
yid = i;
}
}
if(xid !=yid*2) return false;
return true;
}
bool judge5(){
for(int i=1; i<maxn; i++){
if(tr[i] == a){
xid = i;
}
if(tr[i] == b){
yid = i;
}
}
if(xid !=yid*2+1) return false;
return true;
}
bool judge6(){
for(int i=1; i<maxn; i++){
if(tr[i] == a){
xid = i;
}
if(tr[i] == b){
yid = i;
}
}
int depth1=0;
while(xid!=1&&xid!=-1){
depth1++;
xid/=2;
}
while(yid!=1&&yid!=-1){
depth1--;
yid/=2;
}
if(depth1) return false;
return true;
}
int main(){
ios::sync_with_stdio(false);
cls(tr, -1);
cin>>n;
int temp;
for(int i=1; i<=n; i++){
cin>>temp;
build(1, temp);
}
int q;
cin>>q;
string s[10];
bool flag = false;
while(q--){
cin>>a>>s[0];
xid = yid = -1;
flag = false;
if(s[0] == "and"){
cin>>b;
for(int i=1; i<=2; i++){
cin>>s[i];
}
if(s[2] == "siblings"){
if(judge2())flag = true;
}
else{
for(int i=3; i<6; i++) cin>>s[i];
if(judge6())flag = true;
}
}
else{
for(int i=1; i<=2; i++) cin>>s[i];
if(s[2] == "root"){
yid=1;
if(judge1()) flag= true;
}
else if(s[2] == "parent"){
for(int i=3; i<=3; i++) cin>>s[i];
cin>>b;
if(judge3())flag = true;
}
else if(s[2] == "left"){
for(int i=3; i<=4; i++) cin>>s[i];
cin>>b;
if(judge4())flag = true;
}
else if(s[2] == "right"){
for(int i=3; i<=4; i++) cin>>s[i];
cin>>b;
if(judge5())flag = true;
}
}
if(xid==-1||yid==-1){
flag = false;
}
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}