#include<bits/stdc++.h>
using namespace std;
int f[1000010],cnt,k;
string a[1000];
stack<int>c;
int main(){
while(cin>>a[++cnt]){
if(a[cnt][0]>='0'&&a[cnt][0]<='9'){
break;
}
}
int n;
for(int i=0;a[cnt][i]>='0';i++){
n=n*10+a[cnt][i]-'0';
}
cnt--;
for(int i=1;i<=n;i++){
cin>>f[i];
}
cin>>k;
while(k--){
int y;
cin>>y;
f[y]^=1;
for(int k=1;k<=cnt;k++){
if(a[k][0]=='x'){
int o=0;
for(int i=1;i<a[k].size();i++){
o=o*10+a[k][i]-'0';
}
c.push(f[o]);
}
else{
if(a[k][0]=='!'){
int p=c.top();
p^=1;
c.pop();
c.push(p);
}
else if(a[k][0]=='&'){
int a=c.top();
c.pop();
int b=c.top();
c.pop();
c.push(a&b);
}
else if(a[k][0]=='|'){
int a=c.top();
c.pop();
int b=c.top();
c.pop();
c.push(a|b);
}
}
}
f[y]^=1;
cout<<c.top()<<endl;
c.pop();
}
return 0;
}
/*
x1 x2 & x3 |
3
1 0 1
3
1
2
3
x1 ! x2 x4 | x3 x5 ! & & ! &
5
0 1 0 1 1
3
1
3
5
*/