#include <bits/stdc++.h>
using namespace std;
void out() {
  cout.flush();
  cerr << endl << "OUT" << endl;
  int bred;
  cin >> bred;
  exit(0);
}
struct Oper {
  string op, op1, op2, oper;
};
const int MOD = 1000000007;
map<string, int> NUMS;
string t, p;
int n, m;
int a[300500], used[300500];
vector<Oper> opers;
int ress[100500];
int calcKol(int num, int bit) {
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (opers[i].oper == "")
      ress[i] = opers[i].op1[num] - '0';
    else {
      int v1, v2;
      if (opers[i].op1 == "?")
        v1 = bit;
      else
        v1 = ress[NUMS[opers[i].op1]];
      if (opers[i].op2 == "?")
        v2 = bit;
      else
        v2 = ress[NUMS[opers[i].op2]];
      if (opers[i].oper == "AND") ress[i] = (v1 & v2);
      if (opers[i].oper == "XOR") ress[i] = (v1 ^ v2);
      if (opers[i].oper == "OR") ress[i] = (v1 | v2);
    }
    ans += ress[i];
  }
  return ans;
}
void solve() {
  cin >> n >> m;
  string s;
  for (int i = 0; i < n; ++i) {
    Oper oper;
    cin >> s;
    oper.op = s;
    NUMS[s] = i;
    cin >> s >> s;
    if (s[0] == '0' || s[0] == '1') {
      oper.oper = "";
      oper.op1 = s;
    } else {
      oper.op1 = s;
      cin >> oper.oper >> oper.op2;
    }
    opers.push_back(oper);
  }
  vector<int> ansMin, ansMax;
  for (int i = m - 1; i >= 0; --i) {
    int sum0 = calcKol(i, 0);
    int sum1 = calcKol(i, 1);
    ansMin.push_back((sum0 > sum1));
    ansMax.push_back((sum0 < sum1));
  }
  for (int i = m - 1; i >= 0; --i) cout << ansMin[i];
  cout << "\n";
  for (int i = m - 1; i >= 0; --i) cout << ansMax[i];
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  out();
  return 0;
}
