#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using ld = long double;
mt19937 rnd(time(nullptr));
struct Value {
  string b, bit, c;
  int id;
  Value() : b(), bit(), c(), id(0) {}
};
vector<pair<string, Value>> data;
map<string, int> check;
int Eval(int a, int b, string& c) {
  if (c == "AND") return a & b;
  if (c == "OR") return a | b;
  if (c == "XOR") return a ^ b;
  assert(false);
}
bool IsDigit(string& s) { return (s[0] >= '0') && (s[0] <= '9'); }
void DFS(vector<int>& buffer, int v, int i, int value) {
  auto current = data[v].second;
  if ((IsDigit(current.b)) && (IsDigit(current.c))) {
    buffer[v] = Eval(current.b[i] - '0', current.c[i] - '0', current.bit);
  } else if ((IsDigit(current.b)) && (current.c == "?")) {
    buffer[v] = Eval(current.b[i] - '0', value, current.bit);
  } else if ((current.b == "?") && (IsDigit(current.c))) {
    buffer[v] = Eval(current.c[i] - '0', value, current.bit);
  } else if ((current.b == "?") && (current.c == "?")) {
    buffer[v] = Eval(value, value, current.bit);
  } else if ((IsDigit(current.b))) {
    buffer[v] = Eval(current.b[i] - '0', buffer[check[current.c]], current.bit);
  } else if (current.b == "?") {
    buffer[v] = Eval(value, buffer[check[current.c]], current.bit);
  } else if ((IsDigit(current.c))) {
    buffer[v] = Eval(current.c[i] - '0', buffer[check[current.b]], current.bit);
  } else if (current.c == "?") {
    buffer[v] = Eval(value, buffer[check[current.b]], current.bit);
  } else {
    buffer[v] =
        Eval(buffer[check[current.b]], buffer[check[current.c]], current.bit);
  }
}
int Count(int i, int value, int n) {
  vector<int> buffer(n);
  for (int j = 0; j < n; j++) {
    DFS(buffer, j, i, value);
  }
  int result = 0;
  for (auto it : buffer) result += it;
  return result;
}
inline void Solve() {
  int n = 0, m = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string a, b, c, bit, tmp;
    cin >> a >> tmp >> b;
    if (!IsDigit(b)) {
      cin >> bit >> c;
    } else {
      c = b;
      bit = "OR";
    }
    Value buffer;
    buffer.b = b;
    buffer.bit = bit;
    buffer.c = c;
    buffer.id = i;
    data.push_back({a, buffer});
    check[a] = i;
  }
  vector<int> mn(m), mx(m);
  for (int i = 0; i < m; i++) {
    int cnt1 = Count(i, 0, n);
    int cnt2 = Count(i, 1, n);
    if (cnt1 == cnt2) {
      mn[i] = 0;
      mx[i] = 0;
    } else if (cnt1 < cnt2) {
      mn[i] = 0;
      mx[i] = 1;
    } else {
      mn[i] = 1;
      mx[i] = 0;
    }
  }
  for (auto it : mn) cout << it;
  cout << '\n';
  for (auto it : mx) cout << it;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(20);
  Solve();
  return 0;
}
