#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<string> A[N];
vector<int> pq[N];
int n, m;
bool val[N];
inline int fnc(int i, int x) {
  int ans = 0;
  for (__typeof((n)) j = (1); j <= (n); j++) {
    if (A[j].size() == 3) {
      if (!pq[j].empty())
        val[j] = val[pq[j][0]];
      else
        val[j] = A[j][2][0] == '?' ? x : A[j][2][i] - '0';
    } else {
      if (A[j][3] == "XOR") {
        if (pq[j].size() == 0)
          val[j] = (A[j][2][0] == '?' ? x : A[j][2][i] - '0') ^
                   (A[j][4][0] == '?' ? x : A[j][4][i] - '0');
        else if (pq[j].size() == 1) {
          if (A[j][2][0] >= 'a' and A[j][2][0] <= 'z')
            val[j] = val[pq[j][0]] ^ (A[j][4][0] == '?' ? x : A[j][4][i] - '0');
          else
            val[j] = val[pq[j][0]] ^ (A[j][2][0] == '?' ? x : A[j][2][i] - '0');
        } else
          val[j] = val[pq[j][0]] ^ val[pq[j][1]];
      } else if (A[j][3] == "OR") {
        if (pq[j].size() == 0)
          val[j] = (A[j][2][0] == '?' ? x : A[j][2][i] - '0') |
                   (A[j][4][0] == '?' ? x : A[j][4][i] - '0');
        else if (pq[j].size() == 1) {
          if (A[j][2][0] >= 'a' and A[j][2][0] <= 'z')
            val[j] = val[pq[j][0]] | (A[j][4][0] == '?' ? x : A[j][4][i] - '0');
          else
            val[j] = val[pq[j][0]] | (A[j][2][0] == '?' ? x : A[j][2][i] - '0');
        } else
          val[j] = val[pq[j][0]] | val[pq[j][1]];
      } else {
        if (pq[j].size() == 0)
          val[j] = (A[j][2][0] == '?' ? x : A[j][2][i] - '0') &
                   (A[j][4][0] == '?' ? x : A[j][4][i] - '0');
        else if (pq[j].size() == 1) {
          if (A[j][2][0] >= 'a' and A[j][2][0] <= 'z')
            val[j] = val[pq[j][0]] & (A[j][4][0] == '?' ? x : A[j][4][i] - '0');
          else
            val[j] = val[pq[j][0]] & (A[j][2][0] == '?' ? x : A[j][2][i] - '0');
        } else
          val[j] = val[pq[j][0]] & val[pq[j][1]];
      }
    }
    ans += val[j];
  }
  return ans;
}
void solve() {
  string s;
  cin >> n >> m;
  cin.ignore();
  unordered_map<string, int> idx;
  for (__typeof((n)) i = (1); i <= (n); i++) {
    getline(cin, s, '\n');
    stringstream second(s);
    vector<string> v;
    string r;
    while (second >> r) v.push_back(r);
    A[i] = v;
    idx[v[0]] = i;
    if (idx.count(v[2])) pq[i].push_back(idx[v[2]]);
    if (v.size() == 5 and idx.count(v[4])) pq[i].push_back(idx[v[4]]);
  }
  string mn, mx;
  for (__typeof((m - 1)) i = (0); i <= (m - 1); i++) {
    int x = fnc(i, 0);
    int y = fnc(i, 1);
    if (x == y) {
      mn.push_back('0');
      mx.push_back('0');
    } else if (x < y) {
      mn.push_back('0');
      mx.push_back('1');
    } else {
      mn.push_back('1');
      mx.push_back('0');
    }
  }
  cout << mn << "\n" << mx << '\n';
}
signed main() {
  int t;
  ios_base::sync_with_stdio(false);
  t = 1;
  while (t--) solve();
  return 0;
}
