#include<bits/stdc++.h>
using namespace std;
stack<pair<int,pair<int,int> > >q;
int a[5000001];
int t[5000001];
int f[5000001];
int c[5000001];
string k;
int n;
int si(string b){
int h=0;
for(int i=0;i<b.length();i++){
h=h*10+int(b[i]-'0');
}
return h;
}
signed main(){
getline(cin,k);
k+=' ';
scanf("%d",&n);
int len=k.length(),top=0,now=n;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<len;i++){
if(k[i]==' '){
if(k[top]=='x'){
int x=si(k.substr(top+1,(i-1)-top));
f[x]=x;
c[x]=a[x];
q.push(make_pair(x,make_pair(x,x)));
}else if(k[top]=='|'||k[top]=='&'){
int x,y;
x=q.top().first;
q.pop();
y=q.top().first;
q.pop();
int h;
if(k[top]=='|'){
if(c[x]==1&&c[y]==1){
t[x]=1;
t[y]=1;
h=1;
}
if(c[x]==0&&c[y]==0){
t[x]=2;
t[y]=2;
h=0;
}
if(c[x]==1&&c[y]==0){
t[x]=4;
t[y]=1;
h=1;
}
if(c[x]==0&&c[y]==1){
t[x]=1;
t[y]=4;
h=1;
}
}
if(k[top]=='&'){
if(c[x]==1&&c[y]==1){
t[x]=4;
t[y]=4;
h=1;
}
if(c[x]==0&&c[y]==0){
t[x]=0;
t[y]=0;
h=0;
}
if(c[x]==1&&c[y]==0){
t[x]=0;
t[y]=3;
h=0;
}
if(c[x]==0&&c[y]==1){
t[x]=3;
t[y]=0;
h=0;
}
}
now++;
f[x]=now;
f[y]=now;
c[now]=h;
q.push(make_pair(now,make_pair(x,y)));
}else if(k[top]=='!'){
pair<int,pair<int,int> >x=q.top();
c[x.first]=1-c[x.first];
q.pop();
q.push(x);
}
top=i+1;
}
}
int m;
scanf("%d",&m);
for(int i=1;i<=m;i++){
int x;
scanf("%d",&x);
int ans=!c[x],tot=x;
while(tot!=now){
int father=f[tot];
if(ans!=c[now]){
if(t[tot]<=1){
ans=t[tot];
}else if(t[tot]==4){
ans=1-c[father];
}else{
ans=c[father];
}
}else{
if(t[tot]<=1){
ans=t[tot];
}else if(t[tot]==3){
ans=1-c[father];
}else{
ans=c[father];
}
}
tot=father;
}
printf("%d\n",ans);
}
return 0;
}