rt
#include<bits/stdc++.h>
#define read() Read<int>()
namespace pb_ds{
namespace io{
const int MaxBuff=1<<15;
const int Output=1<<23;
char B[MaxBuff],*S=B,*T=B;
#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
char Out[Output],*iter=Out;
inline void flush(){
fwrite(Out,1,iter-Out,stdout);
iter=Out;
}
}
template<class Type> inline Type Read(){
using namespace io;
register char ch;
register Type ans=0;
register bool neg=0;
while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
ch=='-'?neg=1:ans=ch-'0';
while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
return neg?-ans:ans;
}
template<class Type> inline void Print(register Type x,register char ch='\n'){
using namespace io;
if(!x) *iter++='0';
else{
if(x<0) *iter++='-',x=-x;
static int s[100];
register int t=0;
while(x) s[++t]=x%10,x/=10;
while(t) *iter++='0'+s[t--];
}
*iter++=ch;
}
}
using namespace pb_ds;
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
struct node
{
vector<int> a;
int s;
};
stack<node> q;
int n,x[maxn],bk[maxn],ans;
char a[1000005];
void qaq()
{
int l=strlen(a+1);
for(int i=1;i<=l;i++)
{
// cout<<a[i]<<' ';
if(a[i]=='x')
{
int t=0;
while(isdigit(a[++i]))
{
t=t*10+a[i]-'0';
}
vector<int> tmp;
tmp.clear();
tmp.push_back(t);
q.push((node){tmp,x[t]});
// hile()
}
switch(a[i])
{
case '&':{
node t=q.top();q.pop();
node t2=q.top();
q.pop();
if(t.s==0&&t2.s==0)
{
vector<int> wj;
wj.clear();
q.push((node){wj,0});
break;
}
if(t.s==0&&t2.s==1)
{
q.push((node){t.a,0});
break;
}
if(t.s==1&&t2.s==0)
{
q.push((node){t2.a,0});
break;
}
if(t.s==1&&t2.s==1)
{
vector<int> tmp=t.a;
for(int i=t2.a.size()-1;i>=0;i--)
tmp.push_back(t2.a[i]);
q.push((node){tmp,1});
break;
}
break;
}
case '!':{
node tmp=q.top();
q.pop();
tmp.s=tmp.s^1;
q.push(tmp);
break;
}
case '|':{
node t=q.top();q.pop();
node t1=q.top();q.pop();
if(t.s==0&&t1.s==0)
{
vector<int> tmp=t.a;
for(int i=t1.a.size()-1;i>=0;i--)
tmp.push_back(t1.a[i]);
q.push((node){tmp,0});
}
else if(t.s==1&&t1.s==1)
{
vector<int>tmp;
tmp.clear();
q.push((node){tmp,1});
}
else if(t.s==1)
{
q.push((node){t.a,1});
}
else
{
q.push((node){t1.a,t1.s});
}
// cout<<endl<<q.size()<<endl;
break;
}
}
}
node tp=q.top();
for(int i=0;i<=tp.a.size()-1;i++)
{
bk[tp.a[i]]=1;
}
ans=tp.s;
}
int main(){
gets(a+1);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i];
}
qaq();
int q;
cin>>q;
for(int i=1;i<=q;i++)
{
int x;
cin>>x;
if(bk[x])
cout<<(ans^1)<<endl;
else
cout<<ans<<endl;
}
return 0;
}