#include<bits/stdc++.h>
using namespace std;
typedef struct TreeNode *BinTree;
typedef long long ll;
map<ll,int>mp;
struct TreeNode {
int data;
BinTree left;
BinTree right;
BinTree fa;
};
BinTree creatempty() {
BinTree tree=(BinTree)malloc(sizeof(TreeNode));
tree->left=NULL;
tree->right=NULL;
tree->fa=NULL;
return tree;
}
void build(BinTree bt,int x) {
if(x<bt->data) {
if(bt->left==NULL) {
BinTree l=creatempty();
l->data=x;
l->fa=bt;
bt->left=l;
return;
} else {
build(bt->left,x);
}
} else if(x>bt->data) {
if(bt->right==NULL) {
BinTree r=creatempty();
r->data=x;
r->fa=bt;
bt->right=r;
return;
} else {
build(bt->right,x);
}
}
}
int find(BinTree bt,int x,int h) {
if(x<bt->data) return find(bt->left,x,h+1);
if(x>bt->data) return find(bt->right,x,h+1);
if(x==bt->data)return h;
}
BinTree finds(BinTree bt,int x) {
if(x<bt->data)return finds(bt->left,x);
if(x>bt->data)return finds(bt->right,x);
if(x==bt->data)return bt;
}
int main() {
int n,x;
int root;
cin>>n;
cin>>x;
root=x;
mp[x]=1;
BinTree bt=creatempty();
bt->data=x;
for(int i=1; i<n; i++) {
cin>>x;
mp[x]=1;
build(bt,x);
}
int q;
cin>>q;
while(q--) {
int x,y;
cin>>x;
string s;
cin>>s;
if(s[0]=='i') {
cin>>s;
cin>>s;
if(s[0]=='r'&&s[1]=='o') {
if(root==x)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} else if(s[0]=='p') {
cin>>s;
cin>>y;
if(mp[x]&&mp[y]&&y!=root) {
if(finds(bt,y)->fa==finds(bt,x))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} else {
cout<<"No"<<endl;
}
} else if(s[0]=='l') {
cin>>s;
cin>>s;
cin>>y;
if(mp[x]&&mp[y]&&x!=root) {
if(finds(bt,y)->left==finds(bt,x))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} else {
cout<<"No"<<endl;
}
}
else if(s[0]=='r') {
cin>>s;
cin>>s;
cin>>y;
if(mp[x]&&mp[y]&&x!=root) {
if(finds(bt,y)->right==finds(bt,x))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} else {
cout<<"No"<<endl;
}
}
}
else if(s[0]=='a'){
cin>>y;
cin>>s;
cin>>s;
if(s[0]=='s'){
if(mp[x]&&mp[y]&&x!=root&&y!=root) {
if(finds(bt,x)->fa==finds(bt,y)->fa)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} else {
cout<<"No"<<endl;
}
}
else {
cin>>s;
cin>>s;
cin>>s;
if(mp[x]&&mp[y]&&x!=root&&y!=root) {
if(find(bt,x,1)==find(bt,y,1))cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} else {
cout<<"No"<<endl;
}
}
}
}
}