#include <bits/stdc++.h>
using namespace std;
const int maxn = 15010;
const int maxm = 1010;
int zro[maxn][maxm];
int one[maxn][maxm];
int flg[maxn];
map<string, int> MAP;
map<int, string> MAPP;
int cnt;
int id(string s) {
  if (MAP.count(s))
    return MAP[s];
  else
    return MAPP[++cnt] = s, MAP[s] = cnt;
}
int n, m;
vector<int> G[maxn];
string ans[maxn];
int vis[maxn];
string anss, ansb;
void dfs1(int u) {
  vis[u] = 1;
  if (MAPP[u] == "?") {
    for (int i = 0; i < m; i++) zro[u][i] = 0, one[u][i] = 1;
    return;
  }
  if (flg[u] == 0) {
    for (int i = 0; i < (int)ans[u].size(); i++)
      zro[u][i] = one[u][i] = ans[u][i] - '0';
    return;
  }
  int l = G[u][0];
  int r = G[u][1];
  if (!vis[l]) dfs1(l);
  if (!vis[r]) dfs1(r);
  if (flg[u] == 1)
    for (int i = 0; i < m; i++)
      zro[u][i] = zro[l][i] & zro[r][i], one[u][i] = one[l][i] & one[r][i];
  if (flg[u] == 2)
    for (int i = 0; i < m; i++)
      zro[u][i] = zro[l][i] | zro[r][i], one[u][i] = one[l][i] | one[r][i];
  if (flg[u] == 3)
    for (int i = 0; i < m; i++)
      zro[u][i] = zro[l][i] ^ zro[r][i], one[u][i] = one[l][i] ^ one[r][i];
}
void debug() {
  puts("----------------------------------------");
  for (int i = 1; i <= cnt; i++) {
    printf("----------%d ", i);
    cout << MAPP[i] << endl;
    for (int j = 0; j < m; j++)
      printf("%d%c", zro[i][j], j + 1 == m ? '\n' : ' ');
  }
  puts("----------------------------------------");
  puts("----------------------------------------");
  for (int i = 1; i <= cnt; i++) {
    printf("----------%d ", i);
    cout << MAPP[i] << endl;
    for (int j = 0; j < m; j++)
      printf("%d%c", one[i][j], j + 1 == m ? '\n' : ' ');
  }
  puts("----------------------------------------");
}
int main() {
  string a, b, c, d, e;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    cin >> a >> b >> c;
    if (isdigit(c[0]))
      ans[id(a)] = c, flg[id(a)] = 0;
    else {
      cin >> d >> e;
      G[id(a)].push_back(id(c));
      G[id(a)].push_back(id(e));
      if (d == "AND")
        flg[id(a)] = 1;
      else if (d == "OR")
        flg[id(a)] = 2;
      else
        flg[id(a)] = 3;
    }
  }
  for (int i = 1; i <= cnt; i++)
    if (!vis[i]) dfs1(i);
  for (int i = 0; i < m; i++) {
    int cnt0, cnt1;
    cnt0 = cnt1 = 0;
    for (int j = 1; j <= cnt; j++) {
      if (MAPP[j] == "?") continue;
      if (zro[j][i] == 1) cnt0++;
      if (one[j][i] == 1) cnt1++;
    }
    if (cnt1 > cnt0)
      ansb.push_back('1');
    else
      ansb.push_back('0');
    cnt0 = cnt1 = 0;
    for (int j = 1; j <= cnt; j++) {
      if (MAPP[j] == "?") continue;
      if (zro[j][i] == 0) cnt0++;
      if (one[j][i] == 0) cnt1++;
    }
    if (cnt0 >= cnt1)
      anss.push_back('0');
    else
      anss.push_back('1');
  }
  cout << anss << endl << ansb << endl;
  return 0;
}
