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:  Binary number of exactly m bits.  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 011_2, then a = 101_2, b = 011_2, c = 000_2, the sum of their values is 8. If he chooses the number 100_2, then a = 101_2, b = 011_2, c = 111_2, 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.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def sumBin(a, b, varMap):\n  lhs = varMap[a]\n  rhs = varMap[b]\n  return bin(int(lhs, 2) + int(rhs, 2))[2:]\n\ndef andBin(a, b, varMap):\n  lhs = varMap[a]\n  rhs = varMap[b]\n  return bin(int(lhs, 2) & int(rhs, 2))[2:]\n\ndef orBin(a, b, varMap):\n  lhs = varMap[a]\n  rhs = varMap[b]\n  return bin(int(lhs, 2) | int(rhs, 2))[2:]\n\ndef xorBin(a, b, varMap):\n  lhs = varMap[a]\n  rhs = varMap[b]\n  return bin(int(lhs, 2) ^ int(rhs, 2))[2:]\n\nmapOper = {\'AND\': andBin, \'OR\': orBin, \'XOR\' : xorBin}\n\n\nn, m = list(map(int, input().split()))\nminMap = {"?": "0", "": "0"}\nmaxMap = {"?": "1"*m, "": "0"}\n\nminSum = "0"\nmaxSum = "0"\nfor _ in range(n):\n  name, _, expr = input().split(\' \', 2)\n\n  if len(expr.split(\' \')) == 1:\n    minMap[name] = expr\n    maxMap[name] = expr\n  else:\n    lhs, oper, rhs = expr.split()\n    minMap[name] = mapOper[oper](lhs, rhs, minMap).zfill(m)\n    maxMap[name] = mapOper[oper](lhs, rhs, maxMap).zfill(m)\n\n  minSum = sumBin("", name, minMap)\n  maxSum = sumBin("", name, maxMap)\n\n\ndef countOnes(i, varMap):\n  ones = 0\n  for name, num in list(varMap.items()):\n    if name != "?" and name != "":\n      ones += num[i] == "1"\n  return ones\n\nminRes = ""\nmaxRes = ""\n\nfor i in range(m):\n  zeroOnes = countOnes(i, minMap)\n  oneOnes = countOnes(i, maxMap)\n\n  if zeroOnes > oneOnes:\n    maxRes += "0"\n    minRes += "1"\n  elif zeroOnes < oneOnes:\n    maxRes += "1"\n    minRes += "0"\n  else:\n    maxRes += "0"\n    minRes += "0"\n\nprint (minRes)\nprint (maxRes)\n\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14365