#include <bits/stdc++.h>
using namespace std;
int A[200045][2];
int K[200045], type[200045], ans[200045];
string s[200045];
int n, m;
map<string, int> M;
int GetVal(int id, int val) {
  int x1, x2, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (type[i] == 0)
      x1 = (s[i][id] - '0');
    else {
      if (A[i][0] == -1) {
        x1 = val;
      } else
        x1 = ans[A[i][0]];
      if (A[i][1] == -1) {
        x2 = val;
      } else
        x2 = ans[A[i][1]];
      if (K[i] == 0)
        x1 = (x1 & x2);
      else if (K[i] == 1)
        x1 = (x1 | x2);
      else
        x1 = x1 ^ x2;
    }
    ans[i] = x1;
    cnt += x1;
  }
  return cnt;
}
int main() {
  string asn, op1, eq, op2, oper;
  string maxv, minv;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> asn >> eq >> op1;
    M[asn] = i;
    if (op1[0] == '0' || op1[0] == '1') {
      type[i] = 0;
      s[i] = op1;
    } else {
      type[i] = 1;
      if (op1[0] == '?') {
        A[i][0] = -1;
      } else
        A[i][0] = M[op1];
      cin >> oper;
      if (oper[0] == 'A')
        K[i] = 0;
      else if (oper[0] == 'O')
        K[i] = 1;
      else
        K[i] = 2;
      cin >> op2;
      if (op2[0] == '?') {
        A[i][1] = -1;
      } else
        A[i][1] = M[op2];
    }
  }
  for (int i = 0; i < m; i++) {
    int x = GetVal(i, 1);
    int y = GetVal(i, 0);
    if (x > y) {
      maxv += '1';
      minv += '0';
    } else if (y > x) {
      maxv += '0';
      minv += '1';
    } else {
      maxv += '0';
      minv += '0';
    }
  }
  cout << minv << "\n" << maxv << endl;
}
