#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int n, m, a[5123], p1[5123], p2[5123];
string name[5123], s, z[5123], ff[5123], ss[5123], op[5123];
bool b[5123];
vector<pair<string, int> > v;
string ans1, ans2;
int main() {
  ios_base ::sync_with_stdio(false);
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> name[i];
    cin >> s;
    cin >> s;
    v.push_back(make_pair(name[i], i));
    if (s[0] == '1' || s[0] == '0') {
      b[i] = true;
      z[i] = s;
    } else {
      b[i] = false;
      ff[i] = s;
      cin >> op[i] >> ss[i];
    }
  }
  v.push_back(make_pair("?", n));
  sort(v.begin(), v.end());
  pair<string, int> p;
  for (i = 0; i < n; i++)
    if (!b[i]) {
      p = *lower_bound(v.begin(), v.end(), make_pair(ff[i], 0));
      p1[i] = p.second;
      p = *lower_bound(v.begin(), v.end(), make_pair(ss[i], 0));
      p2[i] = p.second;
    }
  for (j = 0; j < m; j++) {
    int c1, c2;
    c1 = c2 = 0;
    a[n] = 0;
    for (i = 0; i < n; i++) {
      if (b[i])
        a[i] = (int)z[i][j] - (int)'0';
      else {
        if (op[i] == "XOR") a[i] = a[p1[i]] ^ a[p2[i]];
        if (op[i] == "AND") a[i] = a[p1[i]] & a[p2[i]];
        if (op[i] == "OR") a[i] = a[p1[i]] | a[p2[i]];
      }
      c1 += a[i];
    }
    a[n] = 1;
    for (i = 0; i < n; i++) {
      if (b[i])
        a[i] = (int)z[i][j] - (int)'0';
      else {
        if (op[i] == "XOR") a[i] = a[p1[i]] ^ a[p2[i]];
        if (op[i] == "AND") a[i] = a[p1[i]] & a[p2[i]];
        if (op[i] == "OR") a[i] = a[p1[i]] | a[p2[i]];
      }
      c2 += a[i];
    }
    if (c1 > c2) {
      ans1 += "0";
      ans2 += "1";
    }
    if (c1 < c2) {
      ans1 += "1";
      ans2 += "0";
    }
    if (c1 == c2) {
      ans1 += "0";
      ans2 += "0";
    }
  }
  cout << ans2 << endl << ans1;
  return 0;
}
