#include <bits/stdc++.h>
using namespace std;
enum op_t { AND = 0, OR, XOR, VAL };
op_t bin_op_from_string(const string& s) {
  if (s == "AND") {
    return AND;
  } else if (s == "OR") {
    return OR;
  } else if (s == "XOR") {
    return XOR;
  } else {
    throw std::runtime_error("Unknown op: " + s);
  }
}
struct Operation {
  op_t op;
  int v1, v2;
  string v;
};
int n, m;
map<string, int> num;
vector<Operation> ops;
vector<int> val;
string min_val, max_val;
bool isNumber(const string& s) {
  for (const char& c : s) {
    if (c < '0' || c > '9') {
      return false;
    }
  }
  return true;
}
int num_from_string(const string& s) {
  if (s == "?") {
    return -1;
  }
  return num[s];
}
int val_from_operand(int v, int x) {
  if (v == -1) {
    return x;
  } else {
    return val[v];
  }
}
int calc(int b, int x) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int v = 0;
    switch (ops[i].op) {
      case VAL:
        v = ops[i].v[b] - '0';
        break;
      case AND:
        v = val_from_operand(ops[i].v1, x) & val_from_operand(ops[i].v2, x);
        break;
      case OR:
        v = val_from_operand(ops[i].v1, x) | val_from_operand(ops[i].v2, x);
        break;
      case XOR:
        v = val_from_operand(ops[i].v1, x) ^ val_from_operand(ops[i].v2, x);
        break;
      default:
        throw std::runtime_error("Unknown op");
    }
    val[i] = v;
    ret += v;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  ops.resize(n);
  min_val.resize(m, '0');
  max_val.resize(m, '1');
  val.resize(n, 0);
  string s, eq, op, v1, v2;
  for (int i = 0; i < n; ++i) {
    cin >> s >> eq >> v1;
    num[s] = i;
    if (isNumber(v1)) {
      ops[i].op = VAL;
      ops[i].v = v1;
    } else {
      cin >> op >> v2;
      ops[i].op = bin_op_from_string(op);
      ops[i].v1 = num_from_string(v1);
      ops[i].v2 = num_from_string(v2);
    }
  }
  for (int i = 0; i < m; ++i) {
    int fst = calc(i, 0);
    int snd = calc(i, 1);
    if (fst < snd) {
      min_val[i] = '0';
      max_val[i] = '1';
    } else if (fst > snd) {
      min_val[i] = '1';
      max_val[i] = '0';
    } else {
      min_val[i] = max_val[i] = '0';
    }
  }
  cout << min_val << endl << max_val << endl;
  return 0;
}
