#include <bits/stdc++.h>
using namespace std;
const int MAX = 5003;
map<string, int> mp;
string tmp;
string mxa = "", mna = "";
string op[MAX];
int name2[MAX];
int name3[MAX];
int arr1[MAX];
int arr2[MAX];
string val1[MAX];
int expre[MAX];
bool check(string s) {
  if (s[0] <= '1' && s[0] >= '0') {
    return true;
  } else {
    return false;
  }
}
int n, m;
void solve(int bit) {
  arr1[0] = 0;
  arr2[0] = 1;
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) {
    if (expre[i]) {
      if (op[i] == "XOR") {
        arr1[i] = arr1[name2[i]] ^ arr1[name3[i]];
        arr2[i] = arr2[name2[i]] ^ arr2[name3[i]];
      } else if (op[i] == "AND") {
        arr1[i] = arr1[name2[i]] & arr1[name3[i]];
        arr2[i] = arr2[name2[i]] & arr2[name3[i]];
      } else if (op[i] == "OR") {
        arr1[i] = arr1[name2[i]] | arr1[name3[i]];
        arr2[i] = arr2[name2[i]] | arr2[name3[i]];
      }
    } else {
      arr1[i] = val1[i][bit] - '0';
      arr2[i] = val1[i][bit] - '0';
    }
    sum1 += arr1[i];
    sum2 += arr2[i];
  }
  if (sum1 >= sum2) {
    mxa += '0';
  } else {
    mxa += '1';
  }
  if (sum1 <= sum2) {
    mna += '0';
  } else {
    mna += '1';
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    cin >> tmp;
    mp[tmp] = i;
    cin >> tmp;
    cin >> tmp;
    val1[i] = tmp;
    if (!check(val1[i])) {
      if (val1[i][0] == '?') {
        name2[i] = 0;
      } else {
        name2[i] = mp[val1[i]];
      }
      cin >> op[i];
      cin >> tmp;
      if (tmp[0] == '?') {
        name3[i] = 0;
      } else {
        name3[i] = mp[tmp];
      }
      expre[i] = 1;
    } else {
      expre[i] = 0;
    }
  }
  for (int i = 0; i < m; i++) {
    solve(i);
  }
  cout << mna << "\n" << mxa << "\n";
  return 0;
}
