#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:133217728")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
const int MAX = 5005;
map<string, int> M;
int a[MAX], b[MAX];
int o[MAX];
string v[MAX];
int n, m;
bool V[MAX];
int test(int idx, bool s) {
  int c = 0;
  for (int i = (0); i < (n); ++i) {
    if (o[i] == -1)
      V[i] = (v[i][idx] == '1');
    else {
      bool A = a[i] == -1 ? s : V[a[i]];
      bool B = b[i] == -1 ? s : V[b[i]];
      if (o[i] == 0)
        V[i] = A && B;
      else if (o[i] == 1)
        V[i] = A || B;
      else
        V[i] = A ^ B;
    }
    c += V[i];
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  string A, B;
  M["?"] = -1;
  for (int i = (0); i < (n); ++i) {
    cin >> A >> B;
    M[A] = i;
    cin >> B;
    if (B[0] == '0' || B[0] == '1')
      v[i] = B, o[i] = -1;
    else {
      a[i] = M[B];
      cin >> A;
      if (A[0] == 'O')
        o[i] = 1;
      else if (A[0] == 'X')
        o[i] = 2;
      cin >> B;
      b[i] = M[B];
    }
  }
  A = B = "";
  for (int i = (0); i < (m); ++i) {
    int Z = test(i, 0);
    int O = test(i, 1);
    A += "01"[O < Z];
    B += "01"[O > Z];
  }
  cout << A << endl << B << endl;
  return 0;
}
