#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
map<string, int> var;
int N, M;
int le[MAXN], ri[MAXN];
string val[MAXN], op[MAXN];
int cur[MAXN];
int compute(int j, int x) {
  int res = 0;
  cur[N] = x;
  for (int i = 0; i < N; i++) {
    if (op[i][0] == 'I') {
      cur[i] = val[i][j] - '0';
    } else if (op[i][0] == 'A') {
      cur[i] = cur[le[i]] & cur[ri[i]];
    } else if (op[i][0] == 'O') {
      cur[i] = cur[le[i]] | cur[ri[i]];
    } else if (op[i][0] == 'X') {
      cur[i] = cur[le[i]] ^ cur[ri[i]];
    }
    res += cur[i];
  }
  return res;
}
void solve(int sgn) {
  for (int j = 0; j < M; j++) {
    int v0 = compute(j, 0);
    int v1 = compute(j, 1);
    if (sgn * v1 < sgn * v0) {
      cout << 1;
    } else {
      cout << 0;
    }
  }
  cout << endl;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    string v;
    cin >> v;
    var[v] = i;
    string tmp;
    cin >> tmp;
    cin >> tmp;
    if (tmp[0] == '0' || tmp[0] == '1') {
      val[i] = tmp;
      op[i] = "ID";
    } else {
      string o, tmp2;
      cin >> o >> tmp2;
      op[i] = o;
      if (tmp[0] == '?') {
        le[i] = N;
      } else {
        le[i] = var[tmp];
      }
      if (tmp2[0] == '?') {
        ri[i] = N;
      } else {
        ri[i] = var[tmp2];
      }
    }
  }
  solve(1);
  solve(-1);
}
