#include <bits/stdc++.h>
using namespace std;
int n, m;
string name[211111], op[211111];
int A[211111], B[211111];
int type[211111];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  map<string, int> mem;
  mem["?"] = -1;
  for (int i = 0; i < n; i++) {
    string temp;
    string q;
    cin >> name[i] >> temp >> q;
    mem[name[i]] = i;
    if (q[0] == '1' || q[0] == '0') {
      type[i] = 1;
      op[i] = q;
    } else {
      A[i] = mem[q];
      cin >> op[i];
      cin >> q;
      B[i] = mem[q];
    }
  }
  string ans1 = "";
  string ans2 = "";
  for (int i = 0; i < m; i++) {
    int val[2];
    for (int j = 0; j < 2; j++) {
      int o[n];
      int sum = 0;
      for (int k = 0; k < n; k++) {
        if (type[k] == 1) {
          o[k] = op[k][i] - '0';
        } else {
          int a, b;
          if (A[k] == -1)
            a = j;
          else
            a = o[A[k]];
          if (B[k] == -1)
            b = j;
          else
            b = o[B[k]];
          if (op[k] == "XOR")
            a ^= b;
          else if (op[k] == "OR")
            a |= b;
          else
            a &= b;
          o[k] = a;
          sum += a;
        }
      }
      val[j] = sum;
    }
    if (val[0] <= val[1])
      ans1.push_back('0');
    else
      ans1.push_back('1');
    if (val[0] >= val[1])
      ans2.push_back('0');
    else
      ans2.push_back('1');
  }
  cout << ans1 << endl;
  cout << ans2 << endl;
  return 0;
}
