#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long pwr(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
bool solve(long long p, long long q, long long a[], long long st, long long n) {
  if (q == 0) return false;
  if (st == n - 1) return (p / q == a[st]) && (p % q == 0);
  if (st == n - 2) {
    if (a[n - 1] == 1) {
      if (p / q == a[st] + 1 && p % q == 0) return true;
      return false;
    }
  }
  if (p / q == a[st]) {
    return solve(q, p - a[st] * q, a, st + 1, n);
  }
  return false;
}
string AND(string &a, string &b) {
  long long m = a.size();
  string ans(m, '0');
  for (long long i = 0; i < m; i++)
    if (a[i] == '1' && b[i] == '1') ans[i] = '1';
  return ans;
}
string OR(string &a, string &b) {
  long long m = a.size();
  string ans(m, '1');
  for (long long i = 0; i < m; i++)
    if (a[i] == '0' && b[i] == '0') ans[i] = '0';
  return ans;
}
string XOR(string &a, string &b) {
  long long m = a.size();
  string ans(m, '0');
  for (long long i = 0; i < m; i++)
    if (a[i] != b[i]) ans[i] = '1';
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string var, temp, fst, op, scn;
  map<string, string> vars1, vars2;
  string x1(m, '0'), x2(m, '1');
  for (long long i = 0; i < n; i++) {
    cin >> var >> temp >> fst;
    if (fst[0] == '0' || fst[0] == '1')
      vars1[var] = vars2[var] = fst;
    else {
      cin >> op >> scn;
      string f1, f2, s1, s2;
      if (fst == "?") {
        f1 = x1;
        f2 = x2;
      } else {
        f1 = vars1[fst];
        f2 = vars2[fst];
      }
      if (scn == "?") {
        s1 = x1;
        s2 = x2;
      } else {
        s1 = vars1[scn];
        s2 = vars2[scn];
      }
      if (op == "AND") {
        vars1[var] = AND(f1, s1);
        vars2[var] = AND(f2, s2);
      } else if (op == "OR") {
        vars1[var] = OR(f1, s1);
        vars2[var] = OR(f2, s2);
      } else if (op == "XOR") {
        vars1[var] = XOR(f1, s1);
        vars2[var] = XOR(f2, s2);
      }
    }
  }
  map<string, string>::iterator it1, it2;
  string ans1(m, '0'), ans2(m, '0');
  for (long long i = 0; i < m; i++) {
    long long cnt1 = 0, cnt2 = 0;
    for (it1 = vars1.begin(), it2 = vars2.begin(); it1 != vars1.end();
         it1++, it2++) {
      if (it1->second[i] == '1') cnt1++;
      if (it2->second[i] == '1') cnt2++;
    }
    if (cnt1 > cnt2)
      ans1[i] = '1';
    else if (cnt1 < cnt2)
      ans2[i] = '1';
  }
  cout << ans1 << '\n' << ans2 << '\n';
}
