#include <bits/stdc++.h>
using namespace std;
int main(){
string expr;
int N,Q;
getline(cin,expr);
cin >> N;
int IDX[N],VALUE[N];
for (int i=0;i<expr.size();i++) if (expr[i]>='0'&&expr[i]<='9') IDX[expr[i]-49] = expr[i]-48;
for (int i=0;i<N;i++) cin >> VALUE[i];
cin >> Q;
int ans[Q],a=0;
for (int i=0;i<Q;i++){
int idx;
cin >> idx;
stack<int> exprstk;
VALUE[idx-1] = (!VALUE[idx-1]);
for (int j=0;j<expr.size();j++){
if (expr[j]>='0'&&expr[j]<='9'){
exprstk.push(VALUE[expr[j]-49]);
}
else if (expr[j]=='&'){
int value1 = exprstk.top();
exprstk.pop();
int value2 = exprstk.top();
exprstk.pop();
exprstk.push(value1&&value2);
}
else if (expr[j]=='|'){
int value1 = exprstk.top();
exprstk.pop();
int value2 = exprstk.top();
exprstk.pop();
exprstk.push(value1||value2);
}
else if (expr[j]=='!'){
int value1 = exprstk.top();
exprstk.pop();
exprstk.push((!value1));
}
}
ans[a++] = exprstk.top();
VALUE[idx-1] = (!VALUE[idx-1]);
}
for (int i=0;i<a;i++) cout << ans[i] << endl;
return 0;
}