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>
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007LL) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1LL;
  long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = mul(_ret, _a, _mod);
  return _ret;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0LL;
  long long _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1) _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
void sleep(double sec = 1021) {
  clock_t s = clock();
  while (clock() - s < CLOCKS_PER_SEC * sec)
    ;
}
int __ = 1, _cs;
string ans[3][1 << 8];
inline int to_int(const string& ss) {
  int ret = 0;
  for (int i = 0; i < 8; i++) ret = (ret << 1) | (ss[i] - '0');
  return ret;
}
inline int Not(int x) { return x ^ ((1 << 8) - 1); }
inline int And(int x, int y) { return x & y; }
inline int Or(int x, int y) { return x | y; }
queue<pair<int, int> > Q;
vector<pair<int, int> > wt;
bool inq[3][1 << 8];
bool gt[3][1 << 8];
void Set(int id, int x, const string& cc) {
  if (ans[id][x].empty() or cc.length() < ans[id][x].length() or
      (cc.length() == ans[id][x].length() and cc < ans[id][x])) {
    ans[id][x] = cc;
    if (not inq[id][x]) {
      Q.push({id, x});
      inq[id][x] = true;
    }
    if (not gt[id][x]) {
      gt[id][x] = true;
      wt.push_back({id, x});
    }
  }
}
inline string to_f(int cur_type, const string& cans) {
  if (cur_type == 1) return cans;
  return "(" + cans + ")";
}
inline string to_t(int cur_type, const string& cans) {
  if (cur_type == 0) return "(" + cans + ")";
  return cans;
}
void build() {
  Set(1, to_int("00001111"), "x");
  Set(1, to_int("00110011"), "y");
  Set(1, to_int("01010101"), "z");
  while (Q.size()) {
    pair<int, int> qq = Q.front();
    Q.pop();
    int type = qq.first;
    int val = qq.second;
    inq[type][val] = false;
    const string& cur = ans[type][val];
    if (type == 1) {
      Set(1, Not(val), "!" + cur);
      Set(2, val, cur);
      Set(0, val, cur);
    }
    if (type == 0) Set(1, val, "(" + cur + ")");
    if (type == 2) Set(0, val, cur);
    for (auto i : wt) {
      int his_type = i.first;
      int his_val = i.second;
      const string& his = ans[his_type][his_val];
      Set(0, Or(val, his_val), cur + "|" + to_t(his_type, his));
      Set(0, Or(his_val, val), his + "|" + to_t(type, cur));
      Set(2, And(val, his_val), to_t(type, cur) + "&" + to_f(his_type, his));
      Set(2, And(his_val, val), to_t(his_type, his) + "&" + to_f(type, cur));
    }
  }
  for (int j = 0; j < 3; j++)
    for (int i = 0; i < (1 << 8); i++) assert(gt[j][i]);
}
string ss;
void init() { cin >> ss; }
void solve() {
  int id = to_int(ss);
  string bst = ans[0][id];
  for (int i = 1; i < 3; i++)
    if (ans[i][id].length() < bst.length() or
        (ans[i][id].length() == bst.length() and ans[i][id] < bst))
      bst = ans[i][id];
  printf("%s\n", bst.c_str());
}
int main() {
  build();
  __ = getint();
  while (__--) {
    init();
    solve();
  }
}
