#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<string> > Qu;
bool isop[5050];
map<string, int> Rev;
int Val[5050];
int ansmi[1050], ansma[1050];
int Calc(int dig, int x) {
  int ret = 0;
  for (int q = 0; q < n; q++) {
    if (!isop[q]) {
      Val[q] = Qu[q][2][dig] - '0';
    } else {
      int d1, d2;
      if (Qu[q][2][0] == '?')
        d1 = x;
      else
        d1 = Val[Rev[Qu[q][2]]];
      if (Qu[q][4][0] == '?')
        d2 = x;
      else
        d2 = Val[Rev[Qu[q][4]]];
      if (Qu[q][3] == "OR") {
        Val[q] = d1 | d2;
      } else if (Qu[q][3] == "AND") {
        Val[q] = d1 & d2;
      } else if (Qu[q][3] == "XOR") {
        Val[q] = d1 ^ d2;
      }
    }
    ret += Val[q];
  }
  return ret;
}
int main(void) {
  cin >> n >> m;
  {
    string buf;
    vector<string> vebuf;
    for (int i = 0; i < n; i++) {
      vebuf.clear();
      for (int j = 0; j < 3; j++) {
        cin >> buf;
        vebuf.push_back(buf);
      }
      if (!isdigit(vebuf[2][0])) {
        isop[i] = true;
        cin >> buf;
        vebuf.push_back(buf);
        cin >> buf;
        vebuf.push_back(buf);
      }
      Rev[vebuf[0]] = i;
      Qu.push_back(vebuf);
    }
  }
  for (int i = 0; i < m; i++) {
    int r0 = Calc(i, 0);
    int r1 = Calc(i, 1);
    if (r0 < r1) ansmi[i] = 0, ansma[i] = 1;
    if (r0 > r1) ansmi[i] = 1, ansma[i] = 0;
    if (r0 == r1) ansmi[i] = 0, ansma[i] = 0;
  }
  for (int i = 0; i < m; i++) cout << ansmi[i];
  cout << endl;
  for (int i = 0; i < m; i++) cout << ansma[i];
  cout << endl;
  return 0;
}
