#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m;
string a, b, c, d, e;
map<string, int> q;
string A[N], B[N], C[N], D[N], E[N];
int l[N], r[N], p[N];
int work(int j, int x) {
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    if (D[i] == "") {
      if (l[i] != 0)
        p[i] = p[l[i]];
      else if (C[i] == "?")
        p[i] = x;
      else
        p[i] = C[i][j] - '0';
    } else {
      int s, t;
      if (l[i] != 0)
        s = p[l[i]];
      else if (C[i] == "?")
        s = x;
      else
        s = C[i][j] - '0';
      if (r[i] != 0)
        t = p[r[i]];
      else if (E[i] == "?")
        t = x;
      else
        t = E[i][j] - '0';
      if (D[i] == "OR")
        p[i] = s | t;
      else if (D[i] == "XOR")
        p[i] = s ^ t;
      else
        p[i] = s & t;
    }
    ret += p[i];
  }
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    if (a == "") cin >> a;
    cin >> b >> c >> d;
    if (d == "OR" || d == "XOR" || d == "AND") {
      cin >> e;
      q[a] = i;
      A[i] = a;
      B[i] = b;
      C[i] = c;
      D[i] = d;
      E[i] = e;
      if (C[i][0] > '1') l[i] = q[C[i]];
      if (E[i][0] > '1') r[i] = q[E[i]];
      a = "";
      d = "";
    } else {
      q[a] = i;
      A[i] = a;
      B[i] = b;
      C[i] = c;
      if (C[i][0] > '1') l[i] = q[C[i]];
      a = d;
      d = "";
    }
  }
  for (int i = 0; i <= m - 1; i++) {
    int cnt0 = work(i, 0), cnt1 = work(i, 1);
    if (cnt0 <= cnt1)
      cout << 0;
    else
      cout << 1;
  }
  puts("");
  for (int i = 0; i <= m - 1; i++) {
    int cnt0 = work(i, 0), cnt1 = work(i, 1);
    if (cnt0 >= cnt1)
      cout << 0;
    else
      cout << 1;
  }
}
