#include <bits/stdc++.h>
using namespace std;
int a[5005][1005], tot, n, m, opt[5005], dui[5005][2];
int ans[1005][2];
map<string, int> mp;
string A;
bool mark[5005];
int doit(int x, int op, int p) {
  if (op == 0)
    return x | p;
  else if (op == 1)
    return x ^ p;
  else
    return x & p;
}
int calc(int x, int p) {
  int re = 0;
  for (int i = 1; i <= n; i++)
    if (mark[i])
      re += a[i][x];
    else {
      int lp;
      if (dui[i][0])
        lp = a[dui[i][0]][x];
      else
        lp = p;
      if (dui[i][1])
        lp = doit(lp, opt[i], a[dui[i][1]][x]);
      else
        lp = doit(lp, opt[i], p);
      re += lp;
      a[i][x] = lp;
    }
  return re;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    cin >> A;
    mp[A] = ++tot;
    cin >> A;
    cin >> A;
    if (A[0] == '0' || A[0] == '1') {
      for (int j = 1; j <= m; j++) a[i][j] = A[j - 1] ^ 48;
      mark[i] = 1;
    } else {
      if (A == "?")
        dui[i][0] = 0;
      else
        dui[i][0] = mp[A];
      cin >> A;
      if (A[0] == 'O')
        opt[i] = 0;
      else if (A[0] == 'X')
        opt[i] = 1;
      else
        opt[i] = 2;
      cin >> A;
      if (A == "?")
        dui[i][1] = 0;
      else
        dui[i][1] = mp[A];
    }
  }
  for (int i = 1; i <= m; i++) {
    int p0 = calc(i, 0), p1 = calc(i, 1);
    if (p0 <= p1)
      ans[i][0] = 0;
    else
      ans[i][0] = 1;
    if (p0 >= p1)
      ans[i][1] = 0;
    else
      ans[i][1] = 1;
  }
  for (int i = 1; i <= m; i++) putchar(ans[i][0] ^ 48);
  putchar('\n');
  for (int i = 1; i <= m; i++) putchar(ans[i][1] ^ 48);
  putchar('\n');
  return 0;
}
