#include <bits/stdc++.h>
const long long int mrx = 1e6 + 5, M = 1e9 + 7, dm = 1e3 + 5;
const long double pi = 3.1415926535897932384626433832795028841971693993751;
long long int mx = -1e18 - 1, mn = 1e18 + 1;
using namespace std;
long long int n, m, ans[mrx], n1[mrx], n2[mrx], s1, s2, res[mrx];
string bi[mrx], ten, ek[mrx], oper[mrx], uc[mrx], minn, maxx;
map<string, long long int> z;
bool flag[mrx];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long int i = 1; i < n + 1; ++i) {
    cin >> bi[i];
    cin >> ten;
    cin >> ek[i];
    z[bi[i]] = i;
    if (ek[i][0] != '0' && ek[i][0] != '1') {
      cin >> oper[i] >> uc[i];
      if (ek[i] == "?") {
        n1[i] = 0;
      } else {
        n1[i] = z[ek[i]];
      }
      if (uc[i] == "?") {
        n2[i] = 0;
      } else {
        n2[i] = z[uc[i]];
      }
      flag[i] = true;
    }
  }
  for (long long int i = 0; i < m; ++i) {
    ans[0] = 0;
    res[0] = 1;
    s1 = 0;
    s2 = 0;
    for (long long int j = 1; j < n + 1; ++j) {
      if (flag[j] == true) {
        if (oper[j] == "XOR") {
          ans[j] = ans[n1[j]] ^ ans[n2[j]];
          res[j] = res[n1[j]] ^ res[n2[j]];
        } else if (oper[j] == "OR") {
          ans[j] = ans[n1[j]] | ans[n2[j]];
          res[j] = res[n1[j]] | res[n2[j]];
        } else {
          ans[j] = ans[n1[j]] & ans[n2[j]];
          res[j] = res[n1[j]] & res[n2[j]];
        }
      } else {
        ans[j] = ek[j][i];
        res[j] = ek[j][i];
      }
      s1 += ans[j];
      s2 += res[j];
    }
    if (s1 <= s2) {
      minn += "0";
    } else {
      minn += "1";
    }
    if (s1 >= s2) {
      maxx += "0";
    } else {
      maxx += "1";
    }
  }
  cout << minn << "\n" << maxx;
  return 0;
}
