#include <bits/stdc++.h>
using namespace std;
void In() { freopen("in.in", "r", stdin); }
void Out() { freopen("out.out", "w", stdout); }
const int N = 5e3 + 10;
const int M = 1e3 + 10;
const int Mbit = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
int val[N][M], op[N], opta[N], optb[N];
int mx[M], mi[M];
int n, m;
char s[1005];
map<string, int> mp;
int cal(int p) {
  int tmp = 0;
  for (int i = 1; i <= n; i++) {
    if (op[i] == 1)
      val[i][p] = (val[opta[i]][p] | val[optb[i]][p]);
    else if (op[i] == 2)
      val[i][p] = (val[opta[i]][p] ^ val[optb[i]][p]);
    else if (op[i] == 3)
      val[i][p] = (val[opta[i]][p] & val[optb[i]][p]);
    tmp += val[i][p];
  }
  return tmp;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    mp["?"] = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%s", s + 1);
      mp[s + 1] = i;
      scanf("%s", s + 1);
      scanf("%s", s + 1);
      if ((s[1] == '0') || (s[1] == '1')) {
        for (int j = 1; j <= m; j++) val[i][j] = s[j] - '0';
        op[i] = 0;
      } else {
        opta[i] = mp[s + 1];
        scanf("%s", s + 1);
        if (s[1] == 'O')
          op[i] = 1;
        else if (s[1] == 'X')
          op[i] = 2;
        else if (s[1] == 'A')
          op[i] = 3;
        scanf("%s", s + 1);
        optb[i] = mp[s + 1];
      }
    }
    for (int i = 1; i <= m; i++) {
      val[0][i] = 0;
      int x0 = cal(i);
      val[0][i] = 1;
      int x1 = cal(i);
      mi[i] = x1 < x0;
      mx[i] = x0 < x1;
    }
    for (int i = 1; i <= m; i++) printf("%d", mi[i]);
    puts("");
    for (int i = 1; i <= m; i++) printf("%d", mx[i]);
    puts("");
  }
  return 0;
}
