#include <bits/stdc++.h>
using namespace std;
inline int gcd(int x, int y) { return y ? gcd(y, ((y + x) % x)) : x; }
int n, m;
map<string, int> mmp;
bitset<1005> bit[5001][2];
int ans[5001][2];
int main() {
  mmp["?"] = 0;
  bit[0][1].set();
  string val, opand, num;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> val >> opand >> num;
    mmp[val] = i + 1;
    if (num[0] == '1' || num[0] == '0') {
      for (int j = 0; j < m; j++) {
        bit[i + 1][0].set(j, num[j] - '0');
        bit[i + 1][1].set(j, num[j] - '0');
      }
    } else {
      cin >> opand >> val;
      for (int j = 0; j <= 1; j++) {
        if (opand == "OR") {
          bit[i + 1][j] = bit[mmp[val]][j] | bit[mmp[num]][j];
        } else if (opand == "XOR") {
          bit[i + 1][j] = bit[mmp[val]][j] ^ bit[mmp[num]][j];
        } else {
          bit[i + 1][j] = bit[mmp[val]][j] & bit[mmp[num]][j];
        }
      }
      for (int j = 0; j < m; j++) {
        for (int k = 0; k <= 1; k++) {
          ans[j][k] += bit[i + 1][k][j];
        }
      }
    }
  }
  for (int i = 0; i < m; i++) {
    cout << (ans[i][0] > ans[i][1]);
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    cout << (ans[i][0] < ans[i][1]);
  }
  cout << endl;
  return 0;
}
