#include <bits/stdc++.h>
using namespace std;
namespace {
template <typename T>
std::ostream &operator<<(std::ostream &, const std::vector<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::deque<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::set<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::stack<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::queue<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::priority_queue<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::unordered_set<T> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::map<T, U> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::unordered_map<T, U> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::pair<T, U> &);
template <typename... T>
std::ostream &operator<<(std::ostream &, const std::tuple<T...> &);
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &, const std::array<T, N> &);
template <typename Tuple, std::size_t N>
struct __TuplePrinter__ {
  static void print(std::ostream &os, const Tuple &t) {
    __TuplePrinter__<Tuple, N - 1>::print(os, t);
    os << ", " << std::get<N - 1>(t);
  }
};
template <typename Tuple>
struct __TuplePrinter__<Tuple, 1> {
  static void print(std::ostream &os, const Tuple &t) { os << std::get<0>(t); }
};
template <typename... T>
std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &t) {
  os << '(';
  __TuplePrinter__<decltype(t), sizeof...(T)>::print(os, t);
  os << ')';
  return os;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &v) {
  return os << '(' << v.first << ", " << v.second << ')';
}
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &os, const std::array<T, N> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::deque<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::stack<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_front(d.top());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::queue<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_back(d.front());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::priority_queue<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_front(d.top());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::unordered_map<T, U> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
}  // namespace
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <signed M, unsigned T>
struct mod_int {
  constexpr static signed MODULO = M;
  constexpr static unsigned TABLE_SIZE = T;
  signed x;
  mod_int() : x(0) {}
  mod_int(long long y)
      : x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}
  mod_int(int y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}
  mod_int &operator+=(const mod_int &rhs) {
    if ((x += rhs.x) >= MODULO) x -= MODULO;
    return *this;
  }
  mod_int &operator-=(const mod_int &rhs) {
    if ((x += MODULO - rhs.x) >= MODULO) x -= MODULO;
    return *this;
  }
  mod_int &operator*=(const mod_int &rhs) {
    x = static_cast<signed>(1LL * x * rhs.x % MODULO);
    return *this;
  }
  mod_int &operator/=(const mod_int &rhs) {
    x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
    return *this;
  }
  mod_int operator-() const { return mod_int(-x); }
  mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
  mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
  mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
  mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
  bool operator<(const mod_int &rhs) const { return x < rhs.x; }
  mod_int inv() const {
    assert(x != 0);
    if (x <= static_cast<signed>(TABLE_SIZE)) {
      if (_inv[1].x == 0) prepare();
      return _inv[x];
    } else {
      signed a = x, b = MODULO, u = 1, v = 0, t;
      while (b) {
        t = a / b;
        a -= t * b;
        std::swap(a, b);
        u -= t * v;
        std::swap(u, v);
      }
      return mod_int(u);
    }
  }
  mod_int pow(long long t) const {
    assert(!(x == 0 && t == 0));
    mod_int e = *this, res = mod_int(1);
    for (; t; e *= e, t >>= 1)
      if (t & 1) res *= e;
    return res;
  }
  mod_int fact() {
    if (_fact[0].x == 0) prepare();
    return _fact[x];
  }
  mod_int inv_fact() {
    if (_fact[0].x == 0) prepare();
    return _inv_fact[x];
  }
  mod_int choose(mod_int y) {
    assert(y.x <= x);
    return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
  }
  static mod_int _inv[TABLE_SIZE + 1];
  static mod_int _fact[TABLE_SIZE + 1];
  static mod_int _inv_fact[TABLE_SIZE + 1];
  static void prepare() {
    _inv[1] = 1;
    for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
      _inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
    }
    _fact[0] = 1;
    for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
      _fact[i] = _fact[i - 1] * int(i);
    }
    _inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
    for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
      _inv_fact[i] = _inv_fact[i + 1] * (i + 1);
    }
  }
};
template <int M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
  return os << rhs.x;
}
template <int M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
  long long s;
  is >> s;
  rhs = mod_int<M, F>(s);
  return is;
}
template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];
template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];
template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];
template <int M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
  return lhs.x == rhs.x;
}
template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
  return !(lhs == rhs);
}
const int MF = 1000010;
const int MOD = 1000000007;
using mint = mod_int<MOD, MF>;
mint binom(int n, int r) {
  return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r);
}
mint fact(int n) { return mint(n).fact(); }
mint inv_fact(int n) { return mint(n).inv_fact(); }
const long long mod = 1000000007;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, pair<string, pair<long long, long long>>>> q;
  vector<pair<long long, string>> d;
  map<string, long long> varlis;
  varlis["?"] = 0;
  long long varnum = 0;
  for (long long i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b >> c;
    if ('0' <= c[0] && c[0] <= '9') {
      varnum += 2;
      varlis[a] = varnum;
      d.push_back({varnum, c});
    } else {
      varnum += 2;
      varlis[a] = varnum;
      string d, e;
      cin >> d >> e;
      q.push_back({varnum, {d, {varlis[c], varlis[e]}}});
    }
  }
  string ansmax = "", ansmin = "";
  for (long long kt = 0; kt < m; kt++) {
    vector<bool> m(n * 2 + 10);
    long long c0 = 0, c1 = 0;
    for (long long i = 0; i < d.size(); i++) {
      long long target = d[i].first;
      string nums = d[i].second;
      long long num = nums[kt] - '0';
      m[target + 1] = num;
      m[target + 0] = num;
    }
    m[0] = 0;
    m[1] = 1;
    for (long long i = 0; i < q.size(); i++) {
      long long var = q[i].first;
      string op = q[i].second.first;
      long long t1 = q[i].second.second.first;
      long long t2 = q[i].second.second.second;
      bool val;
      if (op == "AND") {
        val = m[t1 + 0] & m[t2 + 0];
      }
      if (op == "OR") {
        val = m[t1 + 0] | m[t2 + 0];
      }
      if (op == "XOR") {
        val = m[t1 + 0] ^ m[t2 + 0];
      }
      if (val) c0++;
      m[var + 0] = val;
      if (op == "AND") {
        val = m[t1 + 1] & m[t2 + 1];
      }
      if (op == "OR") {
        val = m[t1 + 1] | m[t2 + 1];
      }
      if (op == "XOR") {
        val = m[t1 + 1] ^ m[t2 + 1];
      }
      if (val) c1++;
      m[var + 1] = val;
    }
    if (c1 < c0)
      ansmin += "1";
    else
      ansmin += "0";
    if (c1 > c0)
      ansmax += "1";
    else
      ansmax += "0";
  }
  cout << ansmin << endl << ansmax << endl;
}

### Prompt

Generate a cpp solution to the following problem:

Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.

Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, Bob computes the values of n variables. Each variable is assigned either a constant m-bit number or result of bitwise operation. Operands of the operation may be either variables defined before, or the number, chosen by Peter. After that, Peter's score equals to the sum of all variable values.

Bob wants to know, what number Peter needs to choose to get the minimum possible score, and what number he needs to choose to get the maximum possible score. In both cases, if there are several ways to get the same score, find the minimum number, which he can choose.

Input

The first line contains two integers n and m, the number of variables and bit depth, respectively (1 ≤ n ≤ 5000; 1 ≤ m ≤ 1000). 

The following n lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of:

  1. Binary number of exactly m bits. 
  2. The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter. 



Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different.

Output

In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as m-bit binary numbers.

Examples

Input

3 3
a := 101
b := 011
c := ? XOR b


Output

011
100


Input

5 1
a := 1
bb := 0
cx := ? OR a
d := ? XOR ?
e := d AND bb


Output

0
0

Note

In the first sample if Peter chooses a number 0112, then a = 1012, b = 0112, c = 0002, the sum of their values is 8. If he chooses the number 1002, then a = 1012, b = 0112, c = 1112, the sum of their values is 15.

For the second test, the minimum and maximum sum of variables a, bb, cx, d and e is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace {
template <typename T>
std::ostream &operator<<(std::ostream &, const std::vector<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::deque<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::set<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::stack<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::queue<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::priority_queue<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::unordered_set<T> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::map<T, U> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::unordered_map<T, U> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::pair<T, U> &);
template <typename... T>
std::ostream &operator<<(std::ostream &, const std::tuple<T...> &);
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &, const std::array<T, N> &);
template <typename Tuple, std::size_t N>
struct __TuplePrinter__ {
  static void print(std::ostream &os, const Tuple &t) {
    __TuplePrinter__<Tuple, N - 1>::print(os, t);
    os << ", " << std::get<N - 1>(t);
  }
};
template <typename Tuple>
struct __TuplePrinter__<Tuple, 1> {
  static void print(std::ostream &os, const Tuple &t) { os << std::get<0>(t); }
};
template <typename... T>
std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &t) {
  os << '(';
  __TuplePrinter__<decltype(t), sizeof...(T)>::print(os, t);
  os << ')';
  return os;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &v) {
  return os << '(' << v.first << ", " << v.second << ')';
}
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &os, const std::array<T, N> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::deque<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::stack<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_front(d.top());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::queue<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_back(d.front());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::priority_queue<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_front(d.top());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::unordered_map<T, U> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
}  // namespace
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <signed M, unsigned T>
struct mod_int {
  constexpr static signed MODULO = M;
  constexpr static unsigned TABLE_SIZE = T;
  signed x;
  mod_int() : x(0) {}
  mod_int(long long y)
      : x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}
  mod_int(int y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}
  mod_int &operator+=(const mod_int &rhs) {
    if ((x += rhs.x) >= MODULO) x -= MODULO;
    return *this;
  }
  mod_int &operator-=(const mod_int &rhs) {
    if ((x += MODULO - rhs.x) >= MODULO) x -= MODULO;
    return *this;
  }
  mod_int &operator*=(const mod_int &rhs) {
    x = static_cast<signed>(1LL * x * rhs.x % MODULO);
    return *this;
  }
  mod_int &operator/=(const mod_int &rhs) {
    x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
    return *this;
  }
  mod_int operator-() const { return mod_int(-x); }
  mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
  mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
  mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
  mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
  bool operator<(const mod_int &rhs) const { return x < rhs.x; }
  mod_int inv() const {
    assert(x != 0);
    if (x <= static_cast<signed>(TABLE_SIZE)) {
      if (_inv[1].x == 0) prepare();
      return _inv[x];
    } else {
      signed a = x, b = MODULO, u = 1, v = 0, t;
      while (b) {
        t = a / b;
        a -= t * b;
        std::swap(a, b);
        u -= t * v;
        std::swap(u, v);
      }
      return mod_int(u);
    }
  }
  mod_int pow(long long t) const {
    assert(!(x == 0 && t == 0));
    mod_int e = *this, res = mod_int(1);
    for (; t; e *= e, t >>= 1)
      if (t & 1) res *= e;
    return res;
  }
  mod_int fact() {
    if (_fact[0].x == 0) prepare();
    return _fact[x];
  }
  mod_int inv_fact() {
    if (_fact[0].x == 0) prepare();
    return _inv_fact[x];
  }
  mod_int choose(mod_int y) {
    assert(y.x <= x);
    return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
  }
  static mod_int _inv[TABLE_SIZE + 1];
  static mod_int _fact[TABLE_SIZE + 1];
  static mod_int _inv_fact[TABLE_SIZE + 1];
  static void prepare() {
    _inv[1] = 1;
    for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
      _inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
    }
    _fact[0] = 1;
    for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
      _fact[i] = _fact[i - 1] * int(i);
    }
    _inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
    for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
      _inv_fact[i] = _inv_fact[i + 1] * (i + 1);
    }
  }
};
template <int M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
  return os << rhs.x;
}
template <int M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
  long long s;
  is >> s;
  rhs = mod_int<M, F>(s);
  return is;
}
template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];
template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];
template <int M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];
template <int M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
  return lhs.x == rhs.x;
}
template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
  return !(lhs == rhs);
}
const int MF = 1000010;
const int MOD = 1000000007;
using mint = mod_int<MOD, MF>;
mint binom(int n, int r) {
  return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r);
}
mint fact(int n) { return mint(n).fact(); }
mint inv_fact(int n) { return mint(n).inv_fact(); }
const long long mod = 1000000007;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, pair<string, pair<long long, long long>>>> q;
  vector<pair<long long, string>> d;
  map<string, long long> varlis;
  varlis["?"] = 0;
  long long varnum = 0;
  for (long long i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b >> c;
    if ('0' <= c[0] && c[0] <= '9') {
      varnum += 2;
      varlis[a] = varnum;
      d.push_back({varnum, c});
    } else {
      varnum += 2;
      varlis[a] = varnum;
      string d, e;
      cin >> d >> e;
      q.push_back({varnum, {d, {varlis[c], varlis[e]}}});
    }
  }
  string ansmax = "", ansmin = "";
  for (long long kt = 0; kt < m; kt++) {
    vector<bool> m(n * 2 + 10);
    long long c0 = 0, c1 = 0;
    for (long long i = 0; i < d.size(); i++) {
      long long target = d[i].first;
      string nums = d[i].second;
      long long num = nums[kt] - '0';
      m[target + 1] = num;
      m[target + 0] = num;
    }
    m[0] = 0;
    m[1] = 1;
    for (long long i = 0; i < q.size(); i++) {
      long long var = q[i].first;
      string op = q[i].second.first;
      long long t1 = q[i].second.second.first;
      long long t2 = q[i].second.second.second;
      bool val;
      if (op == "AND") {
        val = m[t1 + 0] & m[t2 + 0];
      }
      if (op == "OR") {
        val = m[t1 + 0] | m[t2 + 0];
      }
      if (op == "XOR") {
        val = m[t1 + 0] ^ m[t2 + 0];
      }
      if (val) c0++;
      m[var + 0] = val;
      if (op == "AND") {
        val = m[t1 + 1] & m[t2 + 1];
      }
      if (op == "OR") {
        val = m[t1 + 1] | m[t2 + 1];
      }
      if (op == "XOR") {
        val = m[t1 + 1] ^ m[t2 + 1];
      }
      if (val) c1++;
      m[var + 1] = val;
    }
    if (c1 < c0)
      ansmin += "1";
    else
      ansmin += "0";
    if (c1 > c0)
      ansmax += "1";
    else
      ansmax += "0";
  }
  cout << ansmin << endl << ansmax << endl;
}

```