#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10, M = 1e6 + 10, inf = 2147483647;
const long long INF = 1e18 + 10, mod = 2147493647;
map<string, int> mp;
string a[5010][10];
int n, m;
int flag[N];
int check(int beg, int k) {
  memset(flag, 0, sizeof(flag));
  for (int i = 1; i <= n; i++) {
    if (a[i][3][0] == '0' || a[i][3][0] == '1')
      flag[i] = a[i][3][m - k] - '0';
    else {
      int p, q;
      if (a[i][3][0] == '?')
        p = beg;
      else
        p = flag[mp[a[i][3]]];
      if (a[i][5][0] == '?')
        q = beg;
      else
        q = flag[mp[a[i][5]]];
      if (a[i][4][0] == 'A')
        flag[i] = p & q;
      else if (a[i][4][0] == 'O')
        flag[i] = p | q;
      else
        flag[i] = p ^ q;
    }
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) sum += flag[i];
  return sum;
}
int out1[N];
int out2[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 3; j++) cin >> a[i][j];
    mp[a[i][1]] = i;
    if (a[i][3][0] == '0' || a[i][3][0] == '1') continue;
    for (int j = 4; j <= 5; j++) cin >> a[i][j];
  }
  for (int i = 1; i <= m; i++) {
    int p = check(0, i);
    int q = check(1, i);
    if (p > q)
      out2[i] = 0, out1[i] = 1;
    else if (p == q)
      out2[i] = out1[i] = 0;
    else
      out2[i] = 1, out1[i] = 0;
  }
  for (int i = m; i >= 1; i--) printf("%d", out1[i]);
  printf("\n");
  for (int i = m; i >= 1; i--) printf("%d", out2[i]);
  return 0;
}
