#include <bits/stdc++.h>
using namespace std;
int n, m;
struct operacion {
  string op;
  string var, var1, var2;
  vector<int> val;
  operacion() {}
  operacion(string invar, string inval) {
    op = "";
    var = invar;
    for (int i = 0; i < m; i++) val.push_back(inval[i] - '0');
  }
  operacion(string invar, string invar1, string inop, string invar2) {
    op = inop;
    var = invar;
    var1 = invar1;
    var2 = invar2;
  }
};
void escribe(vector<int> v) {
  for (int i = 0; i < m; i++) printf("%d", v[i]);
  printf("\n");
}
void escribe(operacion o) {
  cout << o.var << " := ";
  if (o.op == "")
    escribe(o.val);
  else
    cout << o.var1 << " " << o.op << " " << o.var2 << endl;
}
void escribe(map<string, vector<int> > mapa) {
  cout << "mapa" << endl;
  for (map<string, vector<int> >::iterator it = mapa.begin(); it != mapa.end();
       it++) {
    cout << (it->first) << " = ";
    escribe(it->second);
  }
}
map<string, vector<int> > mapa[2];
vector<operacion> vop;
char buff[10000];
string leer() {
  scanf("%s", buff);
  return string(buff);
}
vector<int> operator|(vector<int> v1, vector<int> v2) {
  for (int i = 0; i < m; i++) v1[i] |= v2[i];
  return v1;
}
vector<int> operator&(vector<int> v1, vector<int> v2) {
  for (int i = 0; i < m; i++) v1[i] &= v2[i];
  return v1;
}
vector<int> operator^(vector<int> v1, vector<int> v2) {
  for (int i = 0; i < m; i++) v1[i] ^= v2[i];
  return v1;
}
int suma(map<string, vector<int> > &mapa, int bit) {
  int s = 0;
  for (map<string, vector<int> >::iterator it = mapa.begin(); it != mapa.end();
       it++)
    if ((it->first) != "?") s += (it->second)[bit];
  return s;
}
vector<int> sol[2];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    string var = leer();
    string asig = leer();
    string var1 = leer();
    if (var1[0] == '0' or var1[0] == '1')
      vop.push_back(operacion(var, var1));
    else {
      string op = leer();
      string var2 = leer();
      vop.push_back(operacion(var, var1, op, var2));
    }
  }
  mapa[0]["?"] = vector<int>(m, 0);
  mapa[1]["?"] = vector<int>(m, 1);
  for (int i = 0; i < n; i++) {
    operacion &op = vop[i];
    if (op.op == "") {
      for (int i = 0; i < 2; i++) mapa[i][op.var] = op.val;
    } else if (op.op == "AND") {
      for (int i = 0; i < 2; i++)
        mapa[i][op.var] = mapa[i][op.var1] & mapa[i][op.var2];
    } else if (op.op == "OR") {
      for (int i = 0; i < 2; i++)
        mapa[i][op.var] = mapa[i][op.var1] | mapa[i][op.var2];
    } else if (op.op == "XOR") {
      for (int i = 0; i < 2; i++)
        mapa[i][op.var] = mapa[i][op.var1] ^ mapa[i][op.var2];
    }
  }
  sol[0] = sol[1] = vector<int>(m);
  for (int i = 0; i < m; i++) {
    int s0 = suma(mapa[0], i);
    int s1 = suma(mapa[1], i);
    if (s0 == s1)
      sol[0][i] = sol[1][i] = 0;
    else if (s0 > s1) {
      sol[0][i] = 1;
      sol[1][i] = 0;
    } else {
      sol[0][i] = 0;
      sol[1][i] = 1;
    }
  }
  escribe(sol[0]);
  escribe(sol[1]);
}
