#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
char s[2001];
bool b[366];
int ind;
int len;
bool eval3();
bool eval(){
bool r;
if(strncmp(s+ind, "NOT", strlen("NOT"))==0){
ind+=strlen("NOT");
r=eval();
return !r;
}
if(s[ind]=='('){
ind++;
r=eval3();
ind++;
}
else if(strncmp(s+ind, "TRUE", strlen("TRUE"))==0){
r=true;
ind+=strlen("TRUE");
}
else if(strncmp(s+ind, "FALSE", strlen("FALSE"))==0){
r=false;
ind+=strlen("FALSE");
}
else{
r=b[s[ind]];
ind++;
}
//if(mod)
//r=!r;
return r;
}
bool eval2(){
bool r=eval();
while(strncmp(s+ind, "AND", strlen("AND"))==0){
ind=ind+strlen("AND");
bool r2=eval();
r=r&&r2;
}
return r;
}
bool eval3(){
bool r=eval2();
while(strncmp(s+ind, "OR", strlen("OR"))==0){
ind=ind+strlen("OR");
bool r2=eval3();
r=r||r2;
}
return r;
}
int main()
{
FILE *fin=fopen("bool.in", "r");
FILE *fout=fopen("bool.out", "w");
char cs[2001];
char *ptr;
int t;
char ch;
fgets(s, 1500, fin);
if(s[strlen(s)-1]=='\n')
s[strlen(s)-1]='\0';
len=strlen(s);
ptr=strchr(s, ' ');
while(ptr){
strcpy(cs, ptr+1);
strcpy(ptr, cs);
ptr=strchr(ptr, ' ');
}
fscanf(fin, "%d\n", &t);
for(int i=1; i<=t; ++i){
fscanf(fin, "%c", &ch);
b[ch] = !b[ch];
ind=0;
if(eval3())
fprintf(fout, "1");
else fprintf(fout, "0");
}
return 0;
}