#include <bits/stdc++.h>
const int N = 200001;
using namespace std;
int f(string &s) {
  long long int pr = 1;
  long long int hash = 0;
  for (char c : s) {
    hash += (c - 'a' + 1) * pr;
    pr = (pr * 33) % 1000000007;
  }
  return hash % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<string, int>> a[n];
  map<string, int> ind;
  long long int hash[n];
  for (int i = 0; i < n; ++i) {
    string var, just, op1, op, op2;
    cin >> var >> just >> op1;
    if (op1[0] == '0' || op1[0] == '1') {
      a[i] = {make_pair(var, 0), make_pair(op1, 0)};
    } else {
      cin >> op >> op2;
      a[i] = {make_pair(var, 0), make_pair(op1, ind[op1]), make_pair(op, 0),
              make_pair(op2, ind[op2])};
    }
    hash[i] = f(var);
    ind[var] = i;
  }
  string all[3] = {"XOR", "OR", "AND"};
  for (int j = 0; j < m; ++j) {
    unordered_map<int, int> d;
    int o = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i].size() == 4) {
        string &op1 = a[i][1].first;
        string &op2 = a[i][3].first;
        string &op = a[i][2].first;
        int fb = (op1 == "?" ? 1 : d[a[i][1].second]);
        int sb = (op2 == "?" ? 1 : d[a[i][3].second]);
        int h;
        if (op == "OR") h = fb | sb;
        if (op == "AND") h = fb & sb;
        if (op == "XOR") h = fb ^ sb;
        o += h;
        d[i] = h;
      } else {
        string &var = a[i][0].first;
        string &op1 = a[i][1].first;
        if (op1[j] == '1') {
          ++o;
          d[i] = 1;
        }
      }
    }
    int z = 0;
    d.clear();
    for (int i = 0; i < n; ++i) {
      if (a[i].size() == 4) {
        string &op1 = a[i][1].first;
        string &op2 = a[i][3].first;
        string &op = a[i][2].first;
        int fb = (op1 == "?" ? 0 : d[a[i][1].second]);
        int sb = (op2 == "?" ? 0 : d[a[i][3].second]);
        int h;
        if (op == "OR") h = fb | sb;
        if (op == "AND") h = fb & sb;
        if (op == "XOR") h = fb ^ sb;
        z += h;
        d[i] = h;
      } else {
        string &var = a[i][0].first;
        string &op1 = a[i][1].first;
        if (op1[j] == '1') {
          ++z;
          d[i] = 1;
        }
      }
    }
    cout << (o < z ? 1 : 0);
  }
  cout << '\n';
  for (int j = 0; j < m; ++j) {
    unordered_map<int, int> d;
    int o = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i].size() == 4) {
        string &op1 = a[i][1].first;
        string &op2 = a[i][3].first;
        string &op = a[i][2].first;
        int fb = (op1 == "?" ? 1 : d[a[i][1].second]);
        int sb = (op2 == "?" ? 1 : d[a[i][3].second]);
        int h;
        if (op == "OR") h = fb | sb;
        if (op == "AND") h = fb & sb;
        if (op == "XOR") h = fb ^ sb;
        o += h;
        d[i] = h;
      } else {
        string &var = a[i][0].first;
        string &op1 = a[i][1].first;
        if (op1[j] == '1') {
          ++o;
          d[i] = 1;
        }
      }
    }
    int z = 0;
    d.clear();
    for (int i = 0; i < n; ++i) {
      if (a[i].size() == 4) {
        string &op1 = a[i][1].first;
        string &op2 = a[i][3].first;
        string &op = a[i][2].first;
        int fb = (op1 == "?" ? 0 : d[a[i][1].second]);
        int sb = (op2 == "?" ? 0 : d[a[i][3].second]);
        int h;
        if (op == "OR") h = fb | sb;
        if (op == "AND") h = fb & sb;
        if (op == "XOR") h = fb ^ sb;
        z += h;
        d[i] = h;
      } else {
        string &var = a[i][0].first;
        string &op1 = a[i][1].first;
        if (op1[j] == '1') {
          ++z;
          d[i] = 1;
        }
      }
    }
    cout << (o > z ? 1 : 0);
  }
}
