#include <bits/stdc++.h>
using namespace std;
const int mod = 100000;
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
inline int read() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  register int x = false;
  register char ch =
      p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
          ? EOF
          : *p1++;
  ;
  register bool sgn = false;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  if (ch == '-')
    sgn = true,
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48),
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  return sgn ? -x : x;
}
long long fpow(long long a, int b, int mod) {
  long long res = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
char s[N];
int a[N], b[N], c[N];
int op[N];
string u[N];
map<string, int> mp;
int main() {
  vector<int> ans1, ans2;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    mp[s] = i;
    scanf("%s", s);
    scanf("%s", s);
    if (s[0] == '1' || s[0] == '0')
      op[i] = 0, u[i] = s;
    else {
      if (s[0] != '?') b[i] = mp[s];
      scanf("%s", s);
      if (s[0] == 'A')
        op[i] = 1;
      else if (s[0] == 'O')
        op[i] = 2;
      else
        op[i] = 3;
      scanf("%s", s);
      if (s[0] != '?') c[i] = mp[s];
    }
  }
  for (int i = 0; i < m; i++) {
    int num1 = 0, num2 = 0;
    a[0] = 0;
    for (int j = 1; j <= n; j++) {
      if (!op[j]) {
        a[j] = u[j][i] - '0';
      } else {
        if (op[j] == 1)
          a[j] = a[b[j]] & a[c[j]];
        else if (op[j] == 2)
          a[j] = a[b[j]] | a[c[j]];
        else
          a[j] = a[b[j]] ^ a[c[j]];
      }
      num1 += a[j];
    }
    a[0] = 1;
    for (int j = 1; j <= n; j++) {
      if (!op[j]) {
        a[j] = u[j][i] - '0';
      } else {
        if (op[j] == 1)
          a[j] = a[b[j]] & a[c[j]];
        else if (op[j] == 2)
          a[j] = a[b[j]] | a[c[j]];
        else
          a[j] = a[b[j]] ^ a[c[j]];
      }
      num2 += a[j];
    }
    if (num1 > num2)
      ans1.push_back(1), ans2.push_back(0);
    else if (num1 == num2)
      ans1.push_back(0), ans2.push_back(0);
    else
      ans1.push_back(0), ans2.push_back(1);
  }
  for (auto &i : ans1) printf("%d", i);
  puts("");
  for (auto &i : ans2) printf("%d", i);
  return 0;
}
