#include <bits/stdc++.h>
using namespace std;
int cnt = -1;
struct node {
  bool op;
  string val;
  int op1, op2;
  int type;
  node() {
    op = 0;
    val = "";
    type = 0;
  }
} m[5020];
map<string, int> ind;
inline int cti(char i) { return (int)(i - '0'); }
vector<string> vct;
bool ansx[2020], ansm[2020];
int tb[5020];
int main() {
  int n, mm;
  string t, p;
  cin >> n >> mm;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (ind.find(t) == ind.end()) {
      ind[t] = ++cnt;
    }
    cin >> p;
    cin >> p;
    if (p[0] == '1' or p[0] == '0') {
      m[cnt].val = p;
      continue;
    }
    m[cnt].op = 1;
    if (p == "?")
      m[cnt].op1 = -1;
    else
      m[cnt].op1 = ind[p];
    cin >> p;
    if (p[0] == 'O') m[cnt].type = 1;
    if (p[0] == 'A') m[cnt].type = 2;
    if (p[0] == 'X') m[cnt].type = 3;
    cin >> p;
    if (p == "?")
      m[cnt].op2 = -1;
    else
      m[cnt].op2 = ind[p];
  }
  int x0, x1, pic1, pic2;
  for (int i = 0; i < mm; i++) {
    x0 = x1 = 0;
    for (int k = 0; k < n; k++) {
      auto j = m[k];
      if (j.op == 0) {
        x0 += cti(j.val[i]);
        tb[k] = cti(j.val[i]);
      } else {
        if (j.op1 == -1)
          pic1 = 0;
        else
          pic1 = tb[j.op1];
        if (j.op2 == -1)
          pic2 = 0;
        else
          pic2 = tb[j.op2];
        if (j.type == 1) {
          x0 += pic1 | pic2;
          tb[k] = pic1 | pic2;
        } else if (j.type == 2) {
          x0 += pic1 & pic2;
          tb[k] = pic1 & pic2;
        } else {
          x0 += pic1 ^ pic2;
          tb[k] = pic1 ^ pic2;
        }
      }
    }
    for (int k = 0; k < n; k++) {
      auto j = m[k];
      if (j.op == 0) {
        x1 += cti(j.val[i]);
        tb[k] = cti(j.val[i]);
      } else {
        if (j.op1 == -1)
          pic1 = 1;
        else
          pic1 = tb[j.op1];
        if (j.op2 == -1)
          pic2 = 1;
        else
          pic2 = tb[j.op2];
        if (j.type == 1) {
          x1 += pic1 | pic2;
          tb[k] = pic1 | pic2;
        } else if (j.type == 2) {
          x1 += pic1 & pic2;
          tb[k] = pic1 & pic2;
        } else {
          x1 += pic1 ^ pic2;
          tb[k] = pic1 ^ pic2;
        }
      }
    }
    if (x0 > x1) {
      ansx[i] = 0;
      ansm[i] = 1;
    }
    if (x0 == x1) {
      ansx[i] = 0;
      ansm[i] = 0;
    }
    if (x0 < x1) {
      ansx[i] = 1;
      ansm[i] = 0;
    }
  }
  for (int i = 0; i < mm; i++) cout << ansm[i];
  cout << endl;
  for (int i = 0; i < mm; i++) cout << ansx[i];
  cout << endl;
}
