#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  string s[n], v[n], a[n], o[n], b[n];
  bool t[n];
  string buf;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
    cin >> buf;
    cin >> buf;
    t[i] = isdigit(buf[0]);
    if (t[i])
      v[i] = buf;
    else {
      a[i] = buf;
      cin >> o[i] >> b[i];
    }
  }
  map<string, long long> ms;
  for (long long i = 0; i < n; i++) ms[s[i]] = i;
  ms["?"] = n;
  string ans, ans2;
  for (long long i = 0; i < m; i++) {
    long long tmp[2] = {};
    long long res[n + 1];
    memset(res, 0, sizeof(res));
    for (long long k = 0; k < 2; k++) {
      res[n] = k;
      for (long long j = 0; j < n; j++) {
        if (t[j]) {
          res[j] = v[j][i] - '0';
          continue;
        }
        long long ba = res[ms[a[j]]], bb = res[ms[b[j]]];
        if (o[j] == "AND") res[j] = ba & bb;
        if (o[j] == "OR") res[j] = ba | bb;
        if (o[j] == "XOR") res[j] = ba ^ bb;
      }
      for (long long j = 0; j < n; j++) tmp[k] += res[j];
    }
    if (tmp[0] <= tmp[1])
      ans += '0';
    else
      ans += '1';
    if (tmp[0] >= tmp[1])
      ans2 += '0';
    else
      ans2 += '1';
  }
  cout << ans << endl << ans2 << endl;
  return 0;
}
