You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of: 

  * Operation AND ('&', ASCII code 38) 
  * Operation OR ('|', ASCII code 124) 
  * Operation NOT ('!', ASCII code 33) 
  * Variables x, y and z (ASCII codes 120-122) 
  * Parentheses ('(', ASCII code 40, and ')', ASCII code 41) 



If more than one expression of minimum length exists, you should find the lexicographically smallest one.

Operations have standard priority. NOT has the highest priority, then AND goes, and OR has the lowest priority. The expression should satisfy the following grammar:

E ::= E '|' T | T

T ::= T '&' F | F

F ::= '!' F | '(' E ')' | 'x' | 'y' | 'z'

Input

The first line contains one integer n — the number of functions in the input (1 ≤ n ≤ 10 000).

The following n lines contain descriptions of functions, the i-th of them contains a string of length 8 that consists of digits 0 and 1 — the truth table of the i-th function. The digit on position j (0 ≤ j < 8) equals to the value of the function in case of <image>, <image> and <image>.

Output

You should output n lines, the i-th line should contain the expression of minimum length which equals to the i-th function. If there is more than one such expression, output the lexicographically smallest of them. Expressions should satisfy the given grammar and shouldn't contain white spaces.

Example

Input

4
00110011
00000111
11110000
00011111


Output

y
(y|z)&amp;x
!x
x|y&amp;z

Note

The truth table for the second function:

<image>
'''
Logical Expression
2018 01 13 
Codeforces Hello 2018 problem E
 - ad hoc, eval, precomputation
 
It takes several minutes to generate all the answers (mainly due to slow eval and myint 
class to override ~operator) so we precompute them all and store answers in source. 
'''
INF = 999999999999999999L
EPS = 1e-12

def read():
    return raw_input().strip()

def read_ints():
    return map(int,read().split())
    
    
class myint(object):
    def __init__(self, val):
        self.val = val 
        
    def __or__(self,y):
        return myint(self.val | y.val)
        
    def __and__(self,y):
        return myint(self.val & y.val)
        
    def __invert__(self):
        return myint(1-self.val)
        
    def __str__(self):
        return str(self.val)

def get_truth_table(expr):
    expr = expr.replace("!","~")
    table_id = 0
    for x in range(2):
        for y in range(2):
            for z in range(2):
                i = 7 - (x*4 + y*2 + z)
                val = eval(expr, {"x":myint(x), "y":myint(y), "z":myint(z)}).val
                table_id |= (1&val)<<i
    return table_id
    
def get_better_expr(a,b):
    if len(a) == 0:
        return b 
    elif len(b) == 0:
        return a 
    elif len(a) < len(b):
        return a 
    elif len(b) < len(a):
        return b 
    else:
        aa = a.replace("~","!")
        bb = b.replace("~","!")
        if aa < bb:
            return a 
        else:
            return b

            
def solve_no_brackets():
    all_tables = [""]*256
    for expr in ["x","y","z","~x","~y","~z"]:
        all_tables[get_truth_table(expr)] = expr
        
    converged = False
    while not converged:
        converged = True 
        for i in range(256):
            for j in range(256):
                if len(all_tables[i]) > 0 and len(all_tables[j]) > 0:
                    new_expr = all_tables[i]+"&"+all_tables[j]
                    new_val = get_truth_table(new_expr)
                    if new_expr != all_tables[new_val] and get_better_expr(all_tables[new_val], new_expr) == new_expr:
                        all_tables[new_val] = new_expr 
                        converged = False 
                        
                    new_expr = all_tables[i]+"|"+all_tables[j]
                    new_val = i|j #because '|' has lowest priority
                    if new_expr != all_tables[new_val] and get_better_expr(all_tables[new_val], new_expr) == new_expr:
                        all_tables[new_val] = new_expr 
                        converged = False 
        print all_tables
    return all_tables
   
def update(all_tables, new_expr, new_val):
    if new_val == -1:
        new_val = get_truth_table(new_expr)
    if new_expr != all_tables[new_val] and get_better_expr(all_tables[new_val], new_expr) == new_expr:
        all_tables[new_val] = new_expr 
        return False 
    else:
        return True
    
def solve_with_brackets(all_tables):
    converged = False 
    while not converged:
        converged = True 
        for i in range(256):
            converged = update(all_tables, "~("+all_tables[i]+")", 255-i) and converged
                
        for i in range(256):
            for j in range(256): 
                converged = update(all_tables, all_tables[i]+"|"+all_tables[j], i|j) and converged
                converged = update(all_tables, "("+all_tables[i]+")&("+all_tables[j]+")", i&j) and converged
                converged = update(all_tables, "~("+all_tables[i]+")&("+all_tables[j]+")", (255-i)&j) and converged
                converged = update(all_tables, "("+all_tables[i]+")&~("+all_tables[j]+")", i&(255-j)) and converged
                converged = update(all_tables, "~("+all_tables[i]+")&~("+all_tables[j]+")", (255-i)&(255-j)) and converged
                    
        for i in range(256):
            for j in range(256): 
                converged = update(all_tables, "("+all_tables[i]+")&"+all_tables[j], -1) and converged
                converged = update(all_tables, all_tables[i] + "&("+all_tables[j]+")", -1) and converged
                converged = update(all_tables, "~("+all_tables[i]+")&"+all_tables[j], -1) and converged
                converged = update(all_tables, all_tables[i] + "&~("+all_tables[j]+")", -1) and converged
                    
        print all_tables
    return all_tables

#all_tables = solve_no_brackets()
#all_tables = solve_with_brackets(all_tables)

all_tables = ['~x&x', 'x&y&z', '~z&x&y', 'x&y', '~y&x&z', 'x&z', '~y&x&z|~z&x&y', '(y|z)&x', '~y&~z&x', '~y&~z&x|x&y&z', '~z&x', '~z&x|x&y', '~y&x', '~y&x|x&z', '~(y&z)&x', 'x', '~x&y&z', 'y&z', '~x&y&z|~z&x&y', '(x|z)&y', '~x&y&z|~y&x&z', '(x|y)&z', '~x&y&z|~y&x&z|~z&x&y', '(x|y)&z|x&y', '~x&y&z|~y&~z&x', '~y&~z&x|y&z', '~x&y&z|~z&x', '~z&x|y&z', '~x&y&z|~y&x', '~y&x|y&z', '~(y&z)&x|~x&y&z', 'x|y&z', '~x&~z&y', '~x&~z&y|x&y&z', '~z&y', '~z&y|x&y', '~x&~z&y|~y&x&z', '~x&~z&y|x&z', '~y&x&z|~z&y', '~z&y|x&z', '~(~x&~y|x&y|z)', '~(~x&~y|x&y|z)|x&y&z', '~z&(x|y)', '~z&(x|y)|x&y', '~x&~z&y|~y&x', '~x&~z&y|~y&x|x&z', '~y&x|~z&y', '~z&y|x', '~x&y', '~x&y|y&z', '~(x&z)&y', 'y', '~x&y|~y&x&z', '~x&y|x&z', '~(x&z)&y|~y&x&z', 'x&z|y', '~x&y|~y&~z&x', '~x&y|~y&~z&x|y&z', '~x&y|~z&x', '~z&x|y', '~x&y|~y&x', '~x&y|~y&x|x&z', '~(x&z)&y|~y&x', 'x|y', '~x&~y&z', '~x&~y&z|x&y&z', '~x&~y&z|~z&x&y', '~x&~y&z|x&y', '~y&z', '~y&z|x&z', '~y&z|~z&x&y', '~y&z|x&y', '~(~x&~z|x&z|y)', '~(~x&~z|x&z|y)|x&y&z', '~x&~y&z|~z&x', '~x&~y&z|~z&x|x&y', '~y&(x|z)', '~y&(x|z)|x&z', '~y&z|~z&x', '~y&z|x', '~x&z', '~x&z|y&z', '~x&z|~z&x&y', '~x&z|x&y', '~(x&y)&z', 'z', '~(x&y)&z|~z&x&y', 'x&y|z', '~x&z|~y&~z&x', '~x&z|~y&~z&x|y&z', '~x&z|~z&x', '~x&z|~z&x|x&y', '~x&z|~y&x', '~y&x|z', '~(x&y)&z|~z&x', 'x|z', '~(~y&~z|x|y&z)', '~(~y&~z|x|y&z)|x&y&z', '~x&~y&z|~z&y', '~x&~y&z|~z&y|x&y', '~x&~z&y|~y&z', '~x&~z&y|~y&z|x&z', '~y&z|~z&y', '~y&z|~z&y|x&y', '~(~x&~y|x&y|z)|~x&~y&z', '~(~x&~y|x&y|z)|~x&~y&z|x&y&z', '~x&~y&z|~z&(x|y)', '~x&~y&z|~z&(x|y)|x&y', '~x&~z&y|~y&(x|z)', '~x&~z&y|~y&(x|z)|x&z', '~y&(x|z)|~z&y', '~y&z|~z&y|x', '~x&(y|z)', '~x&(y|z)|y&z', '~x&z|~z&y', '~x&z|y', '~x&y|~y&z', '~x&y|z', '~(x&y)&z|~z&y', 'y|z', '~x&(y|z)|~y&~z&x', '~x&(y|z)|~y&~z&x|y&z', '~x&(y|z)|~z&x', '~x&z|~z&x|y', '~x&(y|z)|~y&x', '~x&y|~y&x|z', '~x&y|~y&z|~z&x', 'x|y|z', '~(x|y|z)', '~(x|y|z)|x&y&z', '~(~x&y|~y&x|z)', '~(x|y|z)|x&y', '~(~x&z|~z&x|y)', '~(x|y|z)|x&z', '~(~x&y|~y&x|z)|~y&x&z', '~(x|y|z)|(y|z)&x', '~y&~z', '~y&~z|x&y&z', '~(~x&y|z)', '~y&~z|x&y', '~(~x&z|y)', '~y&~z|x&z', '~(~x&y|z)|~y&x', '~y&~z|x', '~(~y&z|~z&y|x)', '~(x|y|z)|y&z', '~(~x&y|~y&x|z)|~x&y&z', '~(x|y|z)|(x|z)&y', '~(~x&z|~z&x|y)|~x&y&z', '~(x|y|z)|(x|y)&z', '~(~x&y|~y&x|z)|~x&y&z|~y&x&z', '~(x|y|z)|(x|y)&z|x&y', '~x&y&z|~y&~z', '~y&~z|y&z', '~(~x&y|z)|~x&y&z', '~(~x&y|z)|y&z', '~(~x&z|y)|~x&y&z', '~(~x&z|y)|y&z', '~(~x&y|z)|~x&y&z|~y&x', '~y&~z|x|y&z', '~x&~z', '~x&~z|x&y&z', '~(~y&x|z)', '~x&~z|x&y', '~x&~z|~y&x&z', '~x&~z|x&z', '~(~y&x|z)|~y&x&z', '~(~y&x|z)|x&z', '~(x&y|z)', '~(x&y|z)|x&y&z', '~z', '~z|x&y', '~x&~z|~y&x', '~(x&y|z)|x&z', '~y&x|~z', '~z|x', '~(~y&z|x)', '~x&~z|y&z', '~(~y&x|z)|~x&y', '~x&~z|y', '~(~y&z|x)|~y&x&z', '~(~y&z|x)|x&z', '~(~y&x|z)|~x&y|~y&x&z', '~x&~z|x&z|y', '~x&y|~y&~z', '~(x&y|z)|y&z', '~x&y|~z', '~z|y', '~(~x&~y&z|x&y)', '~x&~z|~y&x|y&z', '~x&y|~y&x|~z', '~z|x|y', '~x&~y', '~x&~y|x&y&z', '~x&~y|~z&x&y', '~x&~y|x&y', '~(~z&x|y)', '~x&~y|x&z', '~(~z&x|y)|~z&x&y', '~(~z&x|y)|x&y', '~(x&z|y)', '~(x&z|y)|x&y&z', '~x&~y|~z&x', '~(x&z|y)|x&y', '~y', '~y|x&z', '~y|~z&x', '~y|x', '~(~z&y|x)', '~x&~y|y&z', '~(~z&y|x)|~z&x&y', '~(~z&y|x)|x&y', '~(~z&x|y)|~x&z', '~x&~y|z', '~(~z&x|y)|~x&z|~z&x&y', '~x&~y|x&y|z', '~x&z|~y&~z', '~(x&z|y)|y&z', '~(~x&~z&y|x&z)', '~x&~y|~z&x|y&z', '~x&z|~y', '~y|z', '~x&z|~y|~z&x', '~y|x|z', '~(x|y&z)', '~(x|y&z)|x&y&z', '~x&~y|~z&y', '~(x|y&z)|x&y', '~x&~z|~y&z', '~(x|y&z)|x&z', '~(~y&~z&x|y&z)', '~x&~y|~z&y|x&z', '~((x|y)&z|x&y)', '~((x|y)&z|x&y)|x&y&z', '~x&~y|~z', '~x&~y|~z|x&y', '~x&~z|~y', '~x&~z|~y|x&z', '~y|~z', '~y|~z|x', '~x', '~x|y&z', '~x|~z&y', '~x|y', '~x|~y&z', '~x|z', '~x|~y&z|~z&y', '~x|y|z', '~x|~y&~z', '~x|~y&~z|y&z', '~x|~z', '~x|~z|y', '~x|~y', '~x|~y|z', '~(x&y&z)', '~x|x']


n = int(read())
for case in range(n):
    table = int(read(),2)
    print all_tables[table].replace("~","!")

