#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = (int)1e9 + 7;
const int N = 1e6 + 100;
int n;
int op[N];
int zz[N];
int val[N];
char s[10];
vector<int> son[N];
void dfs(int u) {
  for (int i = 0; i < son[u].size(); i++) dfs(son[u][i]);
  if (op[u] == 1) {
    int x = son[u][0], y = son[u][1];
    val[u] = val[x] & val[y];
    if (val[x] == 0 && val[y] == 1) zz[x] = 1;
    if (val[x] == 1 && val[y] == 1) zz[x] = zz[y] = 1;
    if (val[x] == 1 && val[y] == 0) zz[y] = 1;
  } else if (op[u] == 2) {
    int x = son[u][0], y = son[u][1];
    val[u] = val[x] ^ val[y];
    zz[x] = zz[y] = 1;
  } else if (op[u] == 3) {
    int x = son[u][0];
    val[u] = 1 ^ val[x];
    zz[x] = 1;
  } else if (op[u] == 5) {
    int x = son[u][0], y = son[u][1];
    val[u] = val[x] | val[y];
    if (val[x] == 1 && val[y] == 0) zz[x] = 1;
    if (val[x] == 0 && val[y] == 1) zz[y] = 1;
    if (val[x] == 0 && val[y] == 0) zz[x] = zz[y] = 1;
  }
}
void dfs2(int u, int flag) {
  zz[u] &= flag;
  for (int i = 0; i < son[u].size(); i++) dfs2(son[u][i], zz[u]);
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    if (s[1] == 'A') {
      scanf("%d%d", &u, &v);
      son[i].push_back(u);
      son[i].push_back(v);
      op[i] = 1;
    } else if (s[1] == 'X') {
      scanf("%d%d", &u, &v);
      son[i].push_back(u);
      son[i].push_back(v);
      op[i] = 2;
    } else if (s[1] == 'N') {
      scanf("%d", &u);
      son[i].push_back(u);
      op[i] = 3;
    } else if (s[1] == 'I') {
      op[i] = 4;
      scanf("%d", &val[i]);
    } else if (s[1] == 'O') {
      op[i] = 5;
      scanf("%d%d", &u, &v);
      son[i].push_back(u);
      son[i].push_back(v);
    }
  }
  dfs(1);
  zz[1] = 1;
  dfs2(1, 1);
  int ans[2];
  ans[0] = val[1];
  ans[1] = val[1] ^ 1;
  for (int i = 1; i <= n; i++) {
    if (op[i] == 4) {
      printf("%d", ans[zz[i]]);
    }
  }
  return 0;
}
