#include <bits/stdc++.h>
using namespace std;
map<string, int[1001]> mp[2];
int ans[2][1001];
int main() {
  int n, m;
  string v, op, lex, lex2;
  cin >> n >> m;
  char vr[1000], opr[1000], lexr[1000];
  char lex2r[1000];
  int mem[1001], mem2[1001];
  for (int i = 0; i < n; i++) {
    scanf("%s %s %s", &vr, &opr, &lexr);
    v = vr;
    op = opr;
    lex = lexr;
    if (lex[0] >= '0' && lex[0] <= '9') {
      for (int j = 0; j < m; j++) {
        mp[0][v][j] = lex[j] - '0';
        mp[1][v][j] = lex[j] - '0';
      }
    } else {
      scanf("%s %s", &opr, &lex2r);
      op = opr;
      lex2 = lex2r;
      for (int q = 0; q < 2; q++) {
        memcpy(mem, mp[q][lex], m * sizeof(int));
        memcpy(mem2, mp[q][lex2], m * sizeof(int));
        for (int p = 0; p < m; p++) {
          int f_num = 0, s_num = 0;
          if (lex == "?")
            f_num = q;
          else
            f_num = mem[p];
          if (lex2 == "?")
            s_num = q;
          else
            s_num = mem2[p];
          if (op == "OR") {
            mp[q][v][p] = f_num | s_num;
            ans[q][p] += f_num | s_num;
          }
          if (op == "AND") {
            mp[q][v][p] = f_num & s_num;
            ans[q][p] += f_num & s_num;
          }
          if (op == "XOR") {
            mp[q][v][p] = f_num ^ s_num;
            ans[q][p] += f_num ^ s_num;
          }
        }
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (ans[0][i] <= ans[1][i])
      cout << 0;
    else
      cout << 1;
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    if (ans[0][i] >= ans[1][i])
      cout << 0;
    else
      cout << 1;
  }
}
