#include <bits/stdc++.h>
using namespace std;
vector<string> arr[5005];
char tmpp[5005];
unordered_map<string, int> mm;
string ans1, ans2;
int n, m;
int get(string x, int ind) {
  if (x[0] == '0' || x[0] == '1') return x[ind] - '0';
  return mm[x];
}
int get(int x, int val) {
  mm["?"] = val;
  int i;
  for (i = 0; i < n; i++) {
    if (arr[i].size() == 3) {
      mm[arr[i][0]] = arr[i][2][x] - '0';
    } else {
      string a = arr[i][2];
      string b = arr[i][4];
      string op = arr[i][3];
      if (op == "AND")
        mm[arr[i][0]] = get(a, x) & get(b, x);
      else if (op == "OR")
        mm[arr[i][0]] = get(a, x) | get(b, x);
      else
        mm[arr[i][0]] = get(a, x) ^ get(b, x);
    }
  }
  int anss = 0;
  for (i = 0; i < n; i++) anss += mm[arr[i][0]];
  return anss;
}
int main() {
  cin >> n >> m;
  string s;
  getline(cin, s);
  int i;
  for (i = 0; i < n; i++) {
    gets(tmpp);
    s = tmpp;
    stringstream ss;
    ss << s;
    string cur;
    while (ss >> cur) arr[i].push_back(cur);
  }
  for (i = 0; i < m; i++) {
    int a = get(i, 0), b = get(i, 1);
    if (a < b) {
      ans1 += '0';
      ans2 += '1';
    } else if (a == b) {
      ans1 += '0';
      ans2 += '0';
    } else {
      ans1 += '1';
      ans2 += '0';
    }
  }
  printf("%s\n%s\n", ans1.c_str(), ans2.c_str());
}
