#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = (int)3e5 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max() - 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dyy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int s[5005], a[5005];
string op[5005], f[5005];
int b[5005];
void solve() {
  int m, n;
  cin >> n >> m;
  string dump, d1, d2, d3;
  map<string, int> MP;
  MP["?"] = 1;
  for (int i = 1; i <= (n); i++) {
    cin >> d1 >> dump >> d2;
    s[i] = i + 1;
    MP[d1] = s[i];
    if (d2[0] == '0' || d2[0] == '1') {
      op[i] = "-1";
      f[i] = d2;
      continue;
    }
    a[i] = MP[d2];
    cin >> op[i] >> d2;
    b[i] = MP[d2];
  }
  bool ans[m + 5], ans2[m + 5];
  for (int i = 0; i < m; i++) {
    int mp[n + 5];
    mp[1] = 1;
    int a1 = 0;
    for (int j = 1; j <= n; j++) {
      if (op[j] == "-1") {
        mp[s[j]] = f[j][i] - '0';
        continue;
      }
      if (op[j] == "XOR") {
        int A = mp[a[j]] ^ mp[b[j]];
        mp[s[j]] = A;
        if (A) a1++;
      }
      if (op[j] == "OR") {
        int A = mp[a[j]] | mp[b[j]];
        mp[s[j]] = A;
        if (A) a1++;
      }
      if (op[j] == "AND") {
        int A = mp[a[j]] & mp[b[j]];
        mp[s[j]] = A;
        if (A) a1++;
      }
    }
    mp[1] = 0;
    int a2 = 0;
    for (int j = 1; j <= n; j++) {
      if (op[j] == "-1") {
        mp[s[j]] = f[j][i] - '0';
        continue;
      }
      if (op[j] == "XOR") {
        int A = mp[a[j]] ^ mp[b[j]];
        mp[s[j]] = A;
        if (A) a2++;
      }
      if (op[j] == "OR") {
        int A = mp[a[j]] | mp[b[j]];
        mp[s[j]] = A;
        if (A) a2++;
      }
      if (op[j] == "AND") {
        int A = mp[a[j]] & mp[b[j]];
        mp[s[j]] = A;
        if (A) a2++;
      }
    }
    if (a2 <= a1)
      ans[i] = 0;
    else
      ans[i] = 1;
    if (a1 <= a2)
      ans2[i] = 0;
    else
      ans2[i] = 1;
  }
  for (int i = 0; i < (m); i++) cout << ans[i];
  cout << '\n';
  for (int i = 0; i < (m); i++) cout << (ans2[i]);
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  T = 1;
  int CT = 0;
  while (T--) {
    solve();
  }
  return 0;
}
