#include <bits/stdc++.h>
using namespace std;
map<string, int> redir;
string com[5003][3];
char cur1[5003], cur0[5003];
vector<string> cur;
void split(string &s) {
  cur.clear();
  int st = 0;
  for (int i = 0; i < (int)s.size(); ++i)
    if (s[i] == ' ') cur.push_back(s.substr(st, i - st)), st = i + 1;
  cur.push_back(s.substr(st, s.size() - st));
}
pair<int, int> get(int k, int n) {
  int cnt1 = 0, cnt0 = 0;
  for (int i = 0; i < n; ++i) {
    if (com[i][1] == "none") {
      if (com[i][0][k] == '1') ++cnt1, ++cnt0;
      cur1[i] = com[i][0][k];
      cur0[i] = com[i][0][k];
    } else {
      int left1 = (com[i][0] == "?" ? 1 : cur1[redir[com[i][0]]] - '0'),
          left0 = (com[i][0] == "?" ? 0 : cur0[redir[com[i][0]]] - '0'),
          right1 = (com[i][2] == "?" ? 1 : cur1[redir[com[i][2]]] - '0'),
          right0 = (com[i][2] == "?" ? 0 : cur0[redir[com[i][2]]] - '0');
      if (com[i][1] == "AND") {
        cnt1 += left1 & right1;
        cnt0 += left0 & right0;
        cur1[i] = (char)((left1 & right1) + '0');
        cur0[i] = (char)((left0 & right0) + '0');
      } else if (com[i][1] == "OR") {
        cnt1 += left1 | right1;
        cnt0 += left0 | right0;
        cur1[i] = (char)((left1 | right1) + '0');
        cur0[i] = (char)((left0 | right0) + '0');
      } else {
        cnt1 += left1 ^ right1;
        cnt0 += left0 ^ right0;
        cur1[i] = (char)((left1 ^ right1) + '0');
        cur0[i] = (char)((left0 ^ right0) + '0');
      }
    }
  }
  if (cnt1 > cnt0)
    return {0, 1};
  else if (cnt0 > cnt1)
    return {1, 0};
  else
    return {0, 0};
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  string tmp;
  getline(cin, tmp);
  for (int i = 0; i < n; ++i) {
    getline(cin, tmp);
    split(tmp);
    redir[cur[0]] = i;
    if ((int)cur.size() == 3) {
      com[i][0] = cur[2];
      com[i][1] = "none";
    } else {
      com[i][0] = cur[2];
      com[i][1] = cur[3];
      com[i][2] = cur[4];
    }
  }
  string mn = "", mx = "";
  for (int i = 0; i < m; ++i) {
    pair<int, int> tmp = get(i, n);
    mn += (char)(tmp.first + '0');
    mx += (char)(tmp.second + '0');
  }
  cout << mn << '\n' << mx << '\n';
  return 0;
}
