#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int M = 1005;
bool dd[N], codinh[N];
char val[N][M];
vector<int> op[N];
int q[N];
char ss[N], mi[N], ma[N];
int solve(int n, int pos) {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!codinh[i]) {
      int x = val[op[i][0]][pos] - '0';
      int y = val[op[i][1]][pos] - '0';
      if (q[i] == 0) {
        val[i][pos] = (x ^ y) + '0';
      } else if (q[i] == 1) {
        val[i][pos] = (x | y) + '0';
      } else
        val[i][pos] = (x & y) + '0';
    }
    if (val[i][pos] == '1') ans++;
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<string, int> mp;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ss);
    mp[string(ss)] = i;
    scanf("%s", ss);
    scanf("%s", ss);
    if (ss[0] == '0' || ss[0] == '1') {
      codinh[i] = true;
      strcpy(val[i], ss);
    } else {
      if (ss[0] == '?')
        op[i].push_back(0);
      else
        op[i].push_back(mp[string(ss)]);
      scanf("%s", ss);
      if (ss[0] == 'X')
        q[i] = 0;
      else if (ss[0] == 'O')
        q[i] = 1;
      else
        q[i] = 2;
      scanf("%s", ss);
      if (ss[0] == '?')
        op[i].push_back(0);
      else
        op[i].push_back(mp[string(ss)]);
    }
  }
  codinh[0] = true;
  for (int i = 0; i < m; i++) {
    val[0][i] = '0';
    int ans = solve(n, i);
    val[0][i] = '1';
    int tmp = solve(n, i);
    if (ans == tmp) {
      mi[i] = ma[i] = '0';
    } else if (ans < tmp) {
      mi[i] = '0';
      ma[i] = '1';
    } else {
      mi[i] = '1';
      ma[i] = '0';
    }
  }
  mi[m] = ma[m] = 0;
  printf("%s\n%s", mi, ma);
}
