#include <bits/stdc++.h>
#pragma comment(linker, ”/ STACK : 38777216“
using namespace std;
const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n, m, timer = 1;
map<string, int> MP;
int mp[1005][2][5005];
int t1[1005], t2[1005];
int main() {
  scanf("%d%d", &n, &m);
  string answ1 = "", answ2 = "";
  MP["?"] = timer++;
  for (int i = 0; i < m; i++) {
    mp[i][0][1] = 0;
    mp[i][1][1] = 1;
  }
  for (int h = 1; h <= n + 1; h++) {
    char s[2005];
    cin.getline(s, 2005);
    if (h == 1) continue;
    int nn = strlen(s);
    string name = "";
    int l = 0;
    for (int i = 0;; i++) {
      if (s[i] >= 'a' && s[i] <= 'z') {
        name += s[i];
        continue;
      }
      l = i;
      break;
    }
    if (s[l + 4] == '0' || s[l + 4] == '1') {
      for (int i = 0; i < m; i++)
        mp[i][0][timer] = mp[i][1][timer] = s[l + 4 + i] - '0';
      MP[name] = timer++;
    } else {
      string name1 = "", name2 = "";
      for (int i = l + 4;; i++) {
        if (s[i] == ' ') {
          l = i + 1;
          break;
        }
        name1 += s[i];
      }
      int k;
      if (s[l] == 'A') {
        k = 1;
        l += 4;
      }
      if (s[l] == 'O') {
        k = 2;
        l += 3;
      }
      if (s[l] == 'X') {
        k = 3;
        l += 4;
      }
      for (int i = l; i < nn; i++) name2 += s[i];
      int n1 = MP[name1];
      int n2 = MP[name2];
      for (int i = 0; i < m; i++) {
        if (k == 3) {
          int T1 = (mp[i][0][n1] ^ mp[i][0][n2]);
          int T2 = (mp[i][1][n1] ^ mp[i][1][n2]);
          t1[i] += T1;
          t2[i] += T2;
          mp[i][0][timer] = T1;
          mp[i][1][timer] = T2;
        }
        if (k == 1) {
          int T1 = (mp[i][0][n1] & mp[i][0][n2]);
          int T2 = (mp[i][1][n1] & mp[i][1][n2]);
          t1[i] += T1;
          t2[i] += T2;
          mp[i][0][timer] = T1;
          mp[i][1][timer] = T2;
        }
        if (k == 2) {
          int T1 = (mp[i][0][n1] | mp[i][0][n2]);
          int T2 = (mp[i][1][n1] | mp[i][1][n2]);
          t1[i] += T1;
          t2[i] += T2;
          mp[i][0][timer] = T1;
          mp[i][1][timer] = T2;
        }
      }
      MP[name] = timer++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (t1[i] <= t2[i])
      printf("0");
    else
      printf("1");
  }
  cout << endl;
  for (int i = 0; i < m; i++) {
    if (t1[i] >= t2[i])
      printf("0");
    else
      printf("1");
  }
  cout << endl;
  return 0;
}
