#include <bits/stdc++.h>
using namespace std;
const int me = 5025;
int N, M;
int result[2][me];
string lines[me];
vector<string> s[me];
int get(int position, int value) {
  unordered_map<string, int> m;
  m["?"] = value;
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    if ((int)s[i].size() == 3) {
      m[s[i][0]] = s[i][2][position];
      sum += s[i][2][position];
    } else {
      int v;
      if (s[i][3] == "AND") {
        v = (m[s[i][2]] & m[s[i][4]]);
      } else if (s[i][3] == "OR") {
        v = (m[s[i][2]] | m[s[i][4]]);
      } else {
        v = (m[s[i][2]] ^ m[s[i][4]]);
      }
      m[s[i][0]] = v;
      sum += v;
    }
  }
  return sum;
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i <= N; i++) {
    getline(cin, lines[i]);
    string now = "";
    for (char j : lines[i]) {
      if (j == ' ')
        s[i].push_back(now), now = "";
      else
        now += j;
    }
    s[i].push_back(now);
  }
  for (int i = 0; i < M; i++) {
    int g1 = get(i, 0);
    int g2 = get(i, 1);
    if (g1 > g2) {
      result[0][i] = 1;
      result[1][i] = 0;
    } else if (g1 < g2) {
      result[0][i] = 0;
      result[1][i] = 1;
    } else {
      result[0][i] = result[1][i] = 0;
    }
  }
  for (int i = 0; i < M; i++) cout << result[0][i];
  cout << endl;
  for (int i = 0; i < M; i++) cout << result[1][i];
  cout << endl;
  return 0;
}
