#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <time.h>
#include <random>
using namespace std;


mt19937 rnd(time(0)); //rnd()

#define N 1000005

int res[N][2];
int type[N];
int val[N];
int vval[N];
vector <int> childs[N];

int dfs1(int v)
{
	int a, b;
	if (type[v] == 5)
	{
		return vval[v] = val[v];
	}
	else if (type[v] == 4)
	{
		a = dfs1(childs[v][0]);
		return vval[v] = (a ^ 1);
	}
	else if (type[v] == 3)
	{
		a = dfs1(childs[v][0]);
		b = dfs1(childs[v][1]);
		return vval[v] = (a ^ b);
	}
	else if (type[v] == 2)
	{
		a = dfs1(childs[v][0]);
		b = dfs1(childs[v][1]);
		return vval[v] = (a | b);
	}
	else
	{
		a = dfs1(childs[v][0]);
		b = dfs1(childs[v][1]);
		return vval[v] = (a & b);
	}
}

void dfs2(int v, int z, int o)
{
	res[v][0] = z;
	res[v][1] = o;

	if (type[v] == 5)
	{
		return;
	}

	if (type[v] == 4)
	{
		dfs2(childs[v][0], o, z);
		return;
	}

	if (type[v] == 3)
	{
		if (vval[childs[v][1]] == 1)
		{
			dfs2(childs[v][0], o, z);
		}
		else
		{
			dfs2(childs[v][0], z, o);
		}

		if (vval[childs[v][0]] == 1)
		{
			dfs2(childs[v][1], o, z);
		}
		else
		{
			dfs2(childs[v][1], z, o);
		}

		return;
	}

	if (type[v] == 2)
	{
		if (vval[childs[v][1]] == 1)
		{
			dfs2(childs[v][0], o, o);
		}
		else
		{
			dfs2(childs[v][0], z, o);
		}

		if (vval[childs[v][0]] == 1)
		{
			dfs2(childs[v][1], o, o);
		}
		else
		{
			dfs2(childs[v][1], z, o);
		}

		return;
	}

	if (type[v] == 1)
	{
		if (vval[childs[v][1]] == 1)
		{
			dfs2(childs[v][0], z, o);
		}
		else
		{
			dfs2(childs[v][0], z, z);
		}

		if (vval[childs[v][0]] == 1)
		{
			dfs2(childs[v][1], z, o);
		}
		else
		{
			dfs2(childs[v][1], z, z);
		}

		return;
	}

}

int main()
{
	string ss = "put";
	ifstream cin("in" + ss + ".txt");
	ofstream cout("out" + ss + ".txt");


	int n, m, i, j, a, b;
	string s;


	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> s;
		if (s[0] == 'A')
		{
			type[i] = 1;
			cin >> a >> b;
			childs[i].push_back(a);
			childs[i].push_back(b);
		}
		else if (s[0] == 'O')
		{
			type[i] = 2;
			cin >> a >> b;
			childs[i].push_back(a);
			childs[i].push_back(b);
		}
		else if (s[0] == 'X')
		{
			type[i] = 3;
			cin >> a >> b;
			childs[i].push_back(a);
			childs[i].push_back(b);
		}
		else if (s[0] == 'N')
		{
			type[i] = 4;
			cin >> a;
			childs[i].push_back(a);
		}
		else
		{
			type[i] = 5;
			cin >> a;
			val[i] = a;
		}
	}

	dfs1(1);

	dfs2(1, 0, 1);

	for (i = 1; i <= n; i++)
	{
		if (type[i] == 5)
		{
			cout << res[i][(val[i] ^ 1)];
		}
	}

	return 0;
}