#include <bits/stdc++.h>
using namespace std;
vector<tuple<string, string, string, string, string> > v;
unordered_map<string, bool> mp;
int get(int ind, bool c) {
  int sum = 0;
  string var, t, fir, type, sec;
  for (int i = 0; i < v.size(); i++) {
    tie(var, t, fir, type, sec) = v[i];
    if (type == "#")
      mp[var] = (fir[ind] == '1');
    else if (fir != "?" && sec != "?") {
      if (type == "AND")
        mp[var] = (mp[fir] & mp[sec]);
      else if (type == "OR")
        mp[var] = (mp[fir] | mp[sec]);
      else if (type == "XOR")
        mp[var] = (mp[fir] ^ mp[sec]);
    } else if (fir != "?" || sec != "?") {
      if (fir != "?") {
        if (type == "AND")
          mp[var] = (mp[fir] & c);
        else if (type == "OR")
          mp[var] = (mp[fir] | c);
        else if (type == "XOR")
          mp[var] = (mp[fir] ^ c);
      } else {
        if (type == "AND")
          mp[var] = (mp[sec] & c);
        else if (type == "OR")
          mp[var] = (mp[sec] | c);
        else if (type == "XOR")
          mp[var] = (mp[sec] ^ c);
      }
    } else {
      if (type != "XOR")
        mp[var] = c;
      else
        mp[var] = 0;
    }
    if (mp[var]) sum++;
  }
  return sum;
}
int main() {
  int n, m;
  cin >> n >> m;
  string var, t, fir, type, sec;
  while (n--) {
    cin >> var >> t >> fir;
    type = "#";
    if (!isdigit(fir[0])) cin >> type >> sec;
    v.emplace_back(var, t, fir, type, sec);
  }
  string mx = "", mn = "";
  int sum1, sum0;
  for (int i = 0; i < m; i++) {
    sum0 = get(i, 0);
    sum1 = get(i, 1);
    if (sum0 >= sum1)
      mx += '0';
    else
      mx += '1';
    if (sum1 >= sum0)
      mn += '0';
    else
      mn += '1';
  }
  cout << mn << endl << mx << endl;
  return 0;
}
