#include <bits/stdc++.h>
using namespace std;
struct op {
  bool h;
  string v, l, m, r;
  op() {}
  op(string v_, string c) {
    v = v_;
    h = 0;
    string crr = "";
    int i;
    for (i = 1; i < c.size(); i++) {
      if (c[i] == ' ') {
        h = 1;
        break;
      }
      crr += c[i];
    }
    l = crr;
    if (h) {
      crr = "";
      for (i++; i < c.size(); i++) {
        if (c[i] == ' ') {
          break;
        }
        crr += c[i];
      }
      m = crr;
      crr = "";
      for (i++; i < c.size(); i++) {
        if (c[i] == ' ') {
          break;
        }
        crr += c[i];
      }
      r = crr;
    }
  }
  void print() {
    cout << v << " = " << l;
    if (h) {
      cout << "|" << m << "|" << r;
    }
    cout << "\n";
  }
} input[(1 << 20)];
int n, m;
unordered_map<string, char> mm;
bool isDig(string &a) {
  if (a[0] == '0' || a[0] == '1') {
    return 1;
  }
  return 0;
}
string getMin() {
  string resMin;
  string resMax;
  for (int b = 0; b < m; b++) {
    resMin += "Z";
  }
  for (int b = 0; b < m; b++) {
    resMax += "Z";
  }
  for (int b = 0; b < m; b++) {
    int cnt0 = 0, cnt1 = 0;
    mm.clear();
    mm["?"] = '0';
    for (int i = 0; i < n; i++) {
      if (input[i].h == 0) {
        bool br;
        if (isDig(input[i].l)) {
          br = (input[i].l[b] == '1');
        } else {
          br = (mm[input[i].l] == '1');
        }
        if (br) {
          cnt0++;
        }
        mm[input[i].v] = br + '0';
      } else {
        bool b1;
        if (isDig(input[i].l)) {
          b1 = (input[i].l[b] == '1');
        } else {
          b1 = (mm[input[i].l] == '1');
        }
        bool b2;
        if (isDig(input[i].r)) {
          b2 = (input[i].r[b] == '1');
        } else {
          b2 = (mm[input[i].r] == '1');
        }
        bool br;
        if (input[i].m == "AND") {
          br = b1 & b2;
        }
        if (input[i].m == "OR") {
          br = b1 | b2;
        }
        if (input[i].m == "XOR") {
          br = b1 ^ b2;
        }
        if (br) {
          cnt0++;
        }
        mm[input[i].v] = br + '0';
      }
    }
    mm.clear();
    mm["?"] = '1';
    for (int i = 0; i < n; i++) {
      if (input[i].h == 0) {
        bool br;
        if (isDig(input[i].l)) {
          br = (input[i].l[b] == '1');
        } else {
          br = (mm[input[i].l] == '1');
        }
        if (br) {
          cnt1++;
        }
        mm[input[i].v] = br + '0';
      } else {
        bool b1;
        if (isDig(input[i].l)) {
          b1 = (input[i].l[b] == '1');
        } else {
          b1 = (mm[input[i].l] == '1');
        }
        bool b2;
        if (isDig(input[i].r)) {
          b2 = (input[i].r[b] == '1');
        } else {
          b2 = (mm[input[i].r] == '1');
        }
        bool br;
        if (input[i].m == "AND") {
          br = b1 & b2;
        }
        if (input[i].m == "OR") {
          br = b1 | b2;
        }
        if (input[i].m == "XOR") {
          br = b1 ^ b2;
        }
        if (br) {
          cnt1++;
        }
        mm[input[i].v] = br + '0';
      }
    }
    if (cnt0 <= cnt1) {
      resMin[b] = '0';
    } else {
      resMin[b] = '1';
    }
    if (cnt0 >= cnt1) {
      resMax[b] = '0';
    } else {
      resMax[b] = '1';
    }
  }
  cout << resMin << "\n";
  cout << resMax << "\n";
  return "lesh";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string l, eq, r;
    cin >> l >> eq;
    getline(cin, r);
    input[i] = op(l, r);
  }
  getMin();
  return 0;
}
