#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 228;
vector<string> g[N];
vector<int> ids[N];
char temp[N];
int mp[N];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    string line;
    gets(temp);
    line = string(temp);
    line += " ";
    string temp = "";
    for (int j = 0; j < line.size(); j++) {
      if (line[j] == ' ') {
        if (temp.size()) g[i].push_back(temp);
        temp.clear();
      } else {
        temp += line[j];
      }
    }
  }
  unordered_map<string, int> id;
  id["?"] = 0;
  for (int i = 0; i < n; i++) {
    id[g[i][0]] = i + 1;
  }
  for (int j = 0; j < n; j++) {
    if (g[j][2][0] == '0' || g[j][2][0] == '1') {
    } else {
      ids[j].push_back(id[g[j][2]]);
      ids[j].push_back(id[g[j][4]]);
    }
  }
  string ans[2];
  ans[0] = ans[1] = "";
  for (int i = m - 1; i >= 0; i--) {
    int sum = 0;
    mp[0] = 0;
    sum = 0;
    for (int j = 0; j < n; j++) {
      if (g[j][2][0] == '0' || g[j][2][0] == '1') {
        mp[j + 1] = g[j][2][m - i - 1] - '0';
      } else {
        if (g[j][3] == "XOR") {
          mp[j + 1] = mp[ids[j][0]] ^ mp[ids[j][1]];
        } else if (g[j][3] == "AND") {
          mp[j + 1] = mp[ids[j][0]] & mp[ids[j][1]];
        } else if (g[j][3] == "OR") {
          mp[j + 1] = mp[ids[j][0]] | mp[ids[j][1]];
        }
      }
      sum += mp[j + 1];
    }
    pair<int, int> fst, sec;
    fst = make_pair(0, sum);
    mp[0] = 1;
    sum = 0;
    for (int j = 0; j < n; j++) {
      if (g[j][2][0] == '0' || g[j][2][0] == '1') {
        mp[j + 1] = g[j][2][m - i - 1] - '0';
      } else {
        if (g[j][3] == "XOR") {
          mp[j + 1] = mp[ids[j][0]] ^ mp[ids[j][1]];
        } else if (g[j][3] == "AND") {
          mp[j + 1] = mp[ids[j][0]] & mp[ids[j][1]];
        } else if (g[j][3] == "OR") {
          mp[j + 1] = mp[ids[j][0]] | mp[ids[j][1]];
        }
      }
      sum += mp[j + 1];
    }
    sec = make_pair(1, sum);
    if (fst.second == sec.second) {
      ans[0] += "0";
      ans[1] += "0";
    } else if (fst.second < sec.second) {
      ans[0] += "0";
      ans[1] += "1";
    } else if (fst.second > sec.second) {
      ans[1] += "0";
      ans[0] += "1";
    }
  }
  cout << ans[0] << "\n" << ans[1] << "\n";
  return 0;
}
