#include <bits/stdc++.h>
using namespace std;
int n, m;
unordered_map<string, int> id;
vector<int> minAns, maxAns;
struct INPUT {
  string var, left, right, oper;
  INPUT(string _var, string _left, string _right, string _oper)
      : var(_var), left(_left), right(_right), oper(_oper) {}
};
vector<INPUT> input;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string var, tmp, l, r, oper;
    cin >> var >> tmp >> l;
    if (l.front() == '0' || l.front() == '1') {
      input.push_back(INPUT(var, l, "", "0"));
    } else {
      cin >> oper >> r;
      input.push_back(INPUT(var, l, r, oper));
    }
  }
  for (int i = 0; i < m; i++) {
    int cnt[2] = {};
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < n; k++) {
        INPUT current = input[k];
        if (current.left.front() == '0' || current.left.front() == '1') {
          id[current.var] = current.left[i] - '0';
        } else {
          int l, r;
          if (current.left == "?")
            l = j;
          else
            l = id[current.left];
          if (current.right == "?")
            r = j;
          else
            r = id[current.right];
          if (current.oper.front() == 'X')
            id[current.var] = l ^ r;
          else if (current.oper.front() == 'O')
            id[current.var] = l | r;
          else
            id[current.var] = l & r;
        }
        cnt[j] += id[current.var];
      }
    }
    if (cnt[0] == cnt[1])
      minAns.push_back(0), maxAns.push_back(0);
    else if (cnt[0] < cnt[1])
      minAns.push_back(0), maxAns.push_back(1);
    else
      minAns.push_back(1), maxAns.push_back(0);
  }
  for (auto u : minAns) cout << u;
  cout << endl;
  for (auto u : maxAns) cout << u;
  return 0;
}
