#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 5;
const int M = 1000 + 5;
int n, m;
char ss[M << 2];
int Mem[N << 1];
string des[N], op[N], s1[N], s2[N];
int ides[N], is1[N], is2[N];
int Mn[M], Mx[M];
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", ss);
    des[i] = string(ss);
    scanf("%s", ss);
    scanf("%s", ss);
    if (isdigit(ss[0])) {
      op[i] = "=";
      s1[i] = string(ss);
      continue;
    }
    s1[i] = string(ss);
    scanf("%s", ss);
    op[i] = string(ss);
    scanf("%s", ss);
    s2[i] = string(ss);
  }
  int tot = 0;
  map<string, int> mp;
  mp["?"] = ++tot;
  for (int i = 1; i <= n; i++) {
    if (!mp.count(des[i])) {
      mp[des[i]] = ++tot;
    }
    ides[i] = mp[des[i]];
    if (op[i] == "=") continue;
    if (!mp.count(s1[i])) {
      mp[s1[i]] = ++tot;
    }
    is1[i] = mp[s1[i]];
    if (!mp.count(s2[i])) {
      mp[s2[i]] = ++tot;
    }
    is2[i] = mp[s2[i]];
  }
  for (int i = 0; i < m; i++) {
    int now[2] = {0, 0};
    for (int bit = 0; bit < 2; bit++) {
      Mem[1] = bit;
      for (int j = 1; j <= n; j++) {
        if (op[j] == "=") Mem[ides[j]] = s1[j][i] - '0';
        if (op[j] == "AND") Mem[ides[j]] = Mem[is1[j]] & Mem[is2[j]];
        if (op[j] == "OR") Mem[ides[j]] = Mem[is1[j]] | Mem[is2[j]];
        if (op[j] == "XOR") Mem[ides[j]] = Mem[is1[j]] ^ Mem[is2[j]];
        now[bit] += Mem[ides[j]];
      }
    }
    if (now[0] > now[1]) {
      Mx[i] = 0;
      Mn[i] = 1;
    } else if (now[0] == now[1]) {
      Mx[i] = Mn[i] = 0;
    } else {
      Mx[i] = 1;
      Mn[i] = 0;
    }
  }
  for (int i = 0; i < m; i++) putchar(Mn[i] + '0');
  putchar(10);
  for (int i = 0; i < m; i++) putchar(Mx[i] + '0');
  putchar(10);
  return 0;
}
