#include <bits/stdc++.h>
using namespace std;
struct B {
  char all[5005];
} t;
struct A {
  int x, y;
  int which;
  char all[5005];
  B name;
} what[5005];
char temp[5005];
bool operator<(B a, B b) { return (strcmp(a.all, b.all) < 0); }
map<B, int> cha;
char ans[5005];
int main() {
  int N, M, x, y, i, j, a, b;
  scanf("%d %d", &N, &M);
  for (i = 0; i < N; i++) {
    scanf("%s", what[i].name.all);
    cha[what[i].name] = i;
    scanf("%s", temp);
    scanf("%s", temp);
    if (temp[0] == '0' || temp[0] == '1') {
      what[i].which = 0;
      strcpy(what[i].all, temp);
    } else {
      if (temp[0] == '?')
        what[i].x = -1;
      else {
        strcpy(t.all, temp);
        what[i].x = cha[t];
      }
      scanf("%s", temp);
      if (temp[0] == 'A') what[i].which = 1;
      if (temp[0] == 'O') what[i].which = 2;
      if (temp[0] == 'X') what[i].which = 3;
      scanf("%s", temp);
      if (temp[0] == '?')
        what[i].y = -1;
      else {
        strcpy(t.all, temp);
        what[i].y = cha[t];
      }
    }
  }
  for (i = 0; i < M; i++) {
    x = 0;
    y = 0;
    for (j = 0; j < N; j++) {
      if (what[j].which == 0) continue;
      if (what[j].x == -1)
        a = 0;
      else
        a = what[what[j].x].all[i] - '0';
      if (what[j].y == -1)
        b = 0;
      else
        b = what[what[j].y].all[i] - '0';
      if (what[j].which == 1) what[j].all[i] = ((a == 1 && b == 1) + '0');
      if (what[j].which == 2) what[j].all[i] = ((a == 1 || b == 1) + '0');
      if (what[j].which == 3) what[j].all[i] = ((a + b) % 2 + '0');
      if (what[j].all[i] == '1') x++;
    }
    for (j = 0; j < N; j++) {
      if (what[j].which == 0) continue;
      if (what[j].x == -1)
        a = 1;
      else
        a = what[what[j].x].all[i] - '0';
      if (what[j].y == -1)
        b = 1;
      else
        b = what[what[j].y].all[i] - '0';
      if (what[j].which == 1) what[j].all[i] = ((a == 1 && b == 1) + '0');
      if (what[j].which == 2) what[j].all[i] = ((a == 1 || b == 1) + '0');
      if (what[j].which == 3) what[j].all[i] = ((a + b) % 2 + '0');
      if (what[j].all[i] == '1') y++;
    }
    if (x <= y) {
      if (x == y)
        ans[i] = '1';
      else
        ans[i] = '0';
      printf("0");
    } else {
      ans[i] = '1';
      printf("1");
    }
  }
  printf("\n");
  for (i = 0; i < M; i++) printf("%d", 1 - (ans[i] - '0'));
  return 0;
}
