#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
ifstream f("bool.in");
ofstream g("bool.out");
int n,i;
char s[1001],p;
vector<bool> v;
bool orr();
bool andd();
bool variabila();
bool expresie()
{
bool rez=orr();
while(s[i]=='O'&&s[i+1]=='R')
{
i+=3;
rez=rez|orr();
}
return rez;
}
bool orr()
{
bool rez=andd();
while(s[i]=='A'||s[i+1]=='N')
{
i+=4;
rez=rez&andd();
}
return rez;
}
bool andd()
{
bool rez;
if(s[i]=='(')
{
i++;
rez=expresie();
i++;
}
else if(s[i]=='N'&&s[i+1]=='O')
{
i+=4;
rez=!andd();
}
else rez=variabila();
if(s[i]==' ')i++;
return rez;
}
bool variabila()
{
bool rez;
if(!isalpha(s[i+1]))
{
rez=v[(int)s[i]];
i++;
}
else if(s[i]=='T')
{
rez=1;
i+=4;
}
else
{
rez=0;
i+=5;
}
if(s[i]==' ')i++;
return rez;
}
int main()
{
f.getline(s,1000);
f>>n;
v.resize(100,0);
for(int j=1; j<=n; j++)
{
f>>p;
v[p]=v[p]^1;
i=0;
g<<expresie();
}
//cout<<s<<'\n'<<n<<'\n'<<(int)'A';
return 0;
}