#include <bits/stdc++.h>
using namespace std;
inline void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  boostIO();
  int n, m, i, k, cnt[2][5050] = {};
  string var, op, x, y;
  unordered_map<string, bitset<1010>[2]> mp;
  cin >> n >> m;
  mp["?"][0] = 0;
  mp["?"][1].set();
  for (i = 1; i <= n; ++i) {
    cin >> var >> op >> x;
    auto& cur = mp[var];
    if (x[0] == '0' || x[0] == '1') {
      for (k = 0; k < m; ++k) {
        cur[0][k] = x[k] - '0';
        cur[1][k] = x[k] - '0';
      }
    } else {
      cin >> op >> y;
      if (op == "AND") {
        cur[0] = mp[x][0] & mp[y][0];
        cur[1] = mp[x][1] & mp[y][1];
      } else if (op == "OR") {
        cur[0] = mp[x][0] | mp[y][0];
        cur[1] = mp[x][1] | mp[y][1];
      } else {
        cur[0] = mp[x][0] ^ mp[y][0];
        cur[1] = mp[x][1] ^ mp[y][1];
      }
      for (k = 0; k < m; ++k) {
        cnt[0][k] += cur[0][k];
        cnt[1][k] += cur[1][k];
      }
    }
  }
  for (i = 0; i < m; ++i) cout << (cnt[0][i] > cnt[1][i]);
  cout << endl;
  for (i = 0; i < m; ++i) cout << (cnt[0][i] < cnt[1][i]);
  cout << endl;
  return 0;
}
