#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
unordered_map<string, int> id;
int val[maxn * 2];
string lef[maxn], ty[maxn], rig1[maxn], rig2[maxn];
int tot = 0, n, m;
int get_id(const string& s) {
  if (id.count(s)) return id[s];
  return id[s] = ++tot;
}
bool isnum(const string& s) { return isdigit(s[0]); }
int P;
int getv(const string& s) {
  if (isnum(s)) return s[P] - '0';
  return val[get_id(s)];
}
int calc(int p, int v) {
  val[get_id(string("?"))] = v;
  P = p;
  for (int i = 1; i <= n; i++) {
    if (ty[i] == "=") {
      val[get_id(lef[i])] = getv(rig1[i]);
    } else {
      if (ty[i] == "AND") val[get_id(lef[i])] = getv(rig1[i]) & getv(rig2[i]);
      if (ty[i] == "OR") val[get_id(lef[i])] = getv(rig1[i]) | getv(rig2[i]);
      if (ty[i] == "XOR") val[get_id(lef[i])] = getv(rig1[i]) ^ getv(rig2[i]);
    }
  }
  int ans = 0;
  for (int i = 2; i <= tot; i++) ans += val[i];
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    lef[i] = s;
    cin >> s;
    cin >> s;
    if (s[0] == '0' || s[0] == '1') {
      ty[i] = "=";
      rig1[i] = s;
    } else {
      rig1[i] = s;
      cin >> s;
      ty[i] = s;
      cin >> s;
      rig2[i] = s;
    }
  }
  string ans1, ans2;
  for (int i = 0; i < m; i++) {
    int a = calc(i, 0), b = calc(i, 1);
    if (a < b) {
      ans1 += "0";
      ans2 += "1";
    } else if (a > b) {
      ans1 += "1";
      ans2 += "0";
    } else {
      ans1 += "0";
      ans2 += "0";
    }
  }
  cout << ans1 << endl;
  cout << ans2 << endl;
  return 0;
}
