#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1e5+10;
string s;
int n,a[N];
int main() {
freopen("expr.in","r",stdin);
freopen("expr.out","w",stdout);
getline(cin,s);
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int q;
cin>>q;
while(q--) {
int x,t;
cin>>x;
t=a[x];
if(a[x]==0) a[x]=1;
else a[x]=0;
stack<int> st;
for(int i=0;i<(int)s.size();i++) {
if(s[i]==' ') continue;
if(s[i]=='x') {
int sum=0;
i++;
while(s[i]>='0' && s[i]<='9') {
sum=sum*10+s[i]-'0';
i++;
}
i--;
st.push(a[sum]);
}
else {
if(s[i]=='&') {
int b=st.top();st.pop();
int c=st.top();st.pop();
if(b==1 && c==1) st.push(1);
else st.push(0);
}
else if(s[i]=='|') {
int b=st.top();st.pop();
int c=st.top();st.pop();
if(b==0 && c==0) st.push(0);
else st.push(1);
}
else if(s[i]=='!'){
int b=st.top();st.pop();
if(b==0) st.push(1);
else st.push(0);
}
}
}
int ans=st.top();st.pop();
cout<<ans<<endl;
a[x]=t;
}
return 0;
}