#include <bits/stdc++.h>
using namespace std;
long long n, m;
map<string, long long> mp;
struct node {
  string s;
  long long number, x, y, opt;
} digit[5010];
inline long long work(long long x, long long p) {
  digit[0].number = p;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (digit[i].opt == 0)
      digit[i].number = digit[i].s[x] - 48;
    else {
      long long x = digit[digit[i].x].number, y = digit[digit[i].y].number;
      if (digit[i].opt == 1)
        digit[i].number = x & y;
      else if (digit[i].opt == 2)
        digit[i].number = x | y;
      else if (digit[i].opt == 3)
        digit[i].number = x ^ y;
    }
    ans += digit[i].number;
  }
  return ans;
}
int main() {
  cin >> n >> m;
  mp["?"] = 0;
  for (long long i = 1; i <= n; i++) {
    string s;
    cin >> s;
    mp[s] = i;
    cin >> s >> s;
    if (isdigit(s[0])) {
      digit[i].opt = 0;
      digit[i].s = s;
    } else {
      digit[i].x = mp[s];
      cin >> s;
      if (s[0] == 'A')
        digit[i].opt = 1;
      else if (s[0] == 'O')
        digit[i].opt = 2;
      else if (s[0] == 'X')
        digit[i].opt = 3;
      cin >> s;
      digit[i].y = mp[s];
    }
  }
  string ans1 = "", ans2 = "";
  for (long long i = 0; i < m; i++) {
    long long sum1 = work(i, 0), sum2 = work(i, 1);
    if (sum1 <= sum2)
      ans1 += '0';
    else
      ans1 += '1';
    if (sum1 >= sum2)
      ans2 += '0';
    else
      ans2 += '1';
  }
  cout << ans1 << endl << ans2 << endl;
  return 0;
}
