#include <bits/stdc++.h>
using namespace std;
struct Z {
  int a;
  int b;
  int c;
  int d;
} z[10005];
char ans1[5005], ans2[5005];
char x1[5005][1005], x2[5005][1005];
map<string, int> mp;
int main() {
  int n, m;
  cin >> n >> m;
  mp["?"] = 0;
  for (int i = 0; i < n; i++) {
    char s1[5005], s2[5005], s3[5005];
    string s4, s5;
    cin >> s1 >> s2 >> s3;
    mp[s1] = i + 1;
    if (s3[0] == '0' || s3[0] == '1') {
      strcpy(x1[i + 1], s3);
      strcpy(x2[i + 1], s3);
      z[i + 1].a = 0;
    } else {
      cin >> s4 >> s5;
      if (s4 == "OR")
        z[i + 1].a = 1;
      else if (s4 == "XOR")
        z[i + 1].a = 2;
      else
        z[i + 1].a = 3;
      z[i + 1].b = mp[s3];
      z[i + 1].c = mp[s5];
    }
  }
  for (int i = 0; i < m; i++) {
    int s1 = 0, s2 = 0;
    x1[0][i] = '0';
    for (int j = 1; j <= n; j++) {
      if (z[j].a == 0) {
        if (x1[j][i] == '1') s1++;
      } else if (z[j].a == 1) {
        s1 += ((x1[z[j].b][i] - '0') | (x1[z[j].c][i] - '0'));
        x1[j][i] = (x1[z[j].b][i] - '0') | (x1[z[j].c][i] - '0');
      } else if (z[j].a == 2) {
        s1 += ((int)(x1[z[j].b][i] - '0') ^ (int)(x1[z[j].c][i] - '0'));
        x1[j][i] = (x1[z[j].b][i] - '0') ^ (x1[z[j].c][i] - '0');
      } else {
        s1 += ((x1[z[j].b][i] - '0') & (x1[z[j].c][i] - '0'));
        x1[j][i] = (x1[z[j].b][i] - '0') & (x1[z[j].c][i] - '0');
      }
    }
    x2[0][i] = '1';
    for (int j = 1; j <= n; j++) {
      if (z[j].a == 0) {
        if (x2[j][i] == '1') s2++;
      } else if (z[j].a == 1) {
        s2 += ((x2[z[j].b][i] - '0') | (x2[z[j].c][i] - '0'));
        x2[j][i] = (x2[z[j].b][i] - '0') | (x2[z[j].c][i] - '0');
      } else if (z[j].a == 2) {
        s2 += ((x2[z[j].b][i] - '0') ^ (x2[z[j].c][i] - '0'));
        x2[j][i] = (x2[z[j].b][i] - '0') ^ (x2[z[j].c][i] - '0');
      } else {
        s2 += ((x2[z[j].b][i] - '0') & (x2[z[j].c][i] - '0'));
        x2[j][i] = (x2[z[j].b][i] - '0') & (x2[z[j].c][i] - '0');
      }
    }
    if (s1 < s2) {
      ans1[i] = '0';
      ans2[i] = '1';
    } else if (s1 == s2)
      ans1[i] = ans2[i] = '0';
    else {
      ans1[i] = '1';
      ans2[i] = '0';
    }
  }
  for (int i = 0; i < m; i++) cout << ans1[i];
  cout << endl;
  for (int i = 0; i < m; i++) cout << ans2[i];
  cout << endl;
}
