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>
using namespace std;
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
template <class T>
T remin(T &x, T val) {
  if (x > val) {
    x = val;
  }
  return x;
}
template <class T>
T remax(T &x, T val) {
  if (x < val) {
    x = val;
  }
  return x;
}
const int QSIZE = 512;
class ThreadPool {
 public:
  ThreadPool(size_t);
  template <class F, class... Args>
  auto enqueue(F &&f, Args &&...args)
      -> std::future<typename std::result_of<F(Args...)>::type>;
  ~ThreadPool();
  void wait();

 private:
  std::vector<std::thread> workers;
  std::queue<std::function<void()> > tasks;
  std::mutex queue_mutex;
  std::condition_variable condition;
  std::condition_variable condition_size;
  bool stop;
};
inline ThreadPool::ThreadPool(size_t threads) : stop(false) {
  for (size_t i = 0; i < threads; ++i)
    workers.emplace_back([this] {
      for (;;) {
        std::function<void()> task;
        {
          std::unique_lock<std::mutex> lock(this->queue_mutex);
          this->condition.wait(
              lock, [this] { return this->stop || !this->tasks.empty(); });
          if (this->stop && this->tasks.empty()) return;
          task = std::move(this->tasks.front());
          this->tasks.pop();
        }
        task();
        condition_size.notify_all();
      }
    });
}
void ThreadPool::wait() {
  std::unique_lock<std::mutex> lock(queue_mutex);
  condition_size.wait(lock, [this] { return tasks.size() == 0; });
}
template <class F, class... Args>
auto ThreadPool::enqueue(F &&f, Args &&...args)
    -> std::future<typename std::result_of<F(Args...)>::type> {
  using return_type = typename std::result_of<F(Args...)>::type;
  auto task = std::make_shared<std::packaged_task<return_type()> >(
      std::bind(std::forward<F>(f), std::forward<Args>(args)...));
  std::future<return_type> res = task->get_future();
  {
    std::unique_lock<std::mutex> lock(queue_mutex);
    condition_size.wait(lock, [this] { return tasks.size() < QSIZE; });
    if (stop) throw std::runtime_error("enqueue on stopped ThreadPool");
    tasks.emplace([task]() { (*task)(); });
  }
  condition.notify_one();
  return res;
}
inline ThreadPool::~ThreadPool() {
  {
    std::unique_lock<std::mutex> lock(queue_mutex);
    stop = true;
  }
  condition.notify_all();
  for (std::thread &worker : workers) worker.join();
}
mutex ans_update;
const int ALL_MASK = (1 << 8) - 1;
const int X = (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);
const int Y = (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7);
const int Z = (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7);
const int K = 30;
class Checker {
 public:
  string tmp;
  explicit Checker(const string &s) : tmp(s) {}
  int par[K];
  inline void parenthesis() {
    if (tmp.length() == 0) {
      par[0] = -2;
      return;
    }
    for (int i = 0; i < tmp.length(); ++i) {
      par[i] = -1;
    }
    stack<int> par_pos;
    for (int i = 0; i < tmp.length(); ++i) {
      if (tmp[i] == '(') {
        par_pos.push(i);
      } else if (tmp[i] == ')') {
        if (par_pos.empty()) {
          par[0] = -2;
          return;
        } else {
          par[i] = par_pos.top();
          par[par_pos.top()] = i;
          par_pos.pop();
        }
      }
    }
  }
  inline int parse_tok(const char *s, int l, int r) {
    if (l >= r) return -1;
    if (r - l == 1) {
      if (s[l] == 'x' || s[l] == 'y' || s[l] == 'z') {
        if (s[l] == 'x') return X;
        if (s[l] == 'y') return Y;
        if (s[l] == 'z') return Z;
        return -1;
      } else {
        return -1;
      }
    }
    if (s[l] == '(') {
      if (s[r - 1] != ')') {
        return -1;
      }
      return parse(s, l + 1, r - 1);
    }
    if (s[l] == '!') {
      auto res = parse_tok(s, l + 1, r);
      if (res == -1) return -1;
      return res ^ ALL_MASK;
    }
    return -1;
  }
  inline int parse_and(const char *s, int l, int r) {
    if (l >= r) return -1;
    int pos = -1;
    for (int i = l; i < r; ++i) {
      if (par[i] >= 0) {
        i = par[i];
        continue;
      }
      if (s[i] == '&') {
        pos = i;
        break;
      }
    }
    if (pos == -1) {
      return parse_tok(s, l, r);
    } else {
      auto r1 = parse_tok(s, l, pos);
      auto r2 = parse_and(s, pos + 1, r);
      if (r1 == -1 || r2 == -1) return -1;
      return r1 & r2;
    }
  }
  inline int parse(const char *s, int l, int r) {
    if (l >= r) return -1;
    int pos = -1;
    for (int i = l; i < r; ++i) {
      if (par[i] >= 0) {
        i = par[i];
        continue;
      }
      if (s[i] == '|') {
        pos = i;
        break;
      }
    }
    if (pos == -1) {
      return parse_and(s, l, r);
    } else {
      auto r1 = parse_and(s, l, pos);
      auto r2 = parse(s, pos + 1, r);
      if (r1 == -1 || r2 == -1) return -1;
      return r1 | r2;
    }
  }
};
const int N = 1 << 8;
string ans[N];
int CNT = 0;
int len;
char buf[K];
string symbols;
unordered_map<char, string> to;
inline int parse_calc(const std::string &s) {
  Checker checker(s);
  checker.parenthesis();
  if (checker.par[0] == -2) return -1;
  return checker.parse(checker.tmp.data(), 0,
                       static_cast<int>(checker.tmp.length()));
}
void check(const string &s) {
  int val = parse_calc(s);
  if (val == -1) {
    return;
  }
  assert(val < N);
  unique_lock<mutex> lock(ans_update);
  if (ans[val].empty()) {
    ans[val] = s;
    ++CNT;
  } else {
    if (ans[val].length() == len) {
      if (ans[val] > s) {
        ans[val] = s;
      }
    } else if (ans[val].length() > len) {
      ans[val] = s;
    }
  }
}
ThreadPool pool(2);
void gen(int p = 0, int cnt = 0) {
  if (cnt < 0) {
    return;
  }
  if (cnt - (len - p) > 0) {
    return;
  }
  if (p == len) {
    if (cnt == 0) {
      buf[p] = 0;
      string s = buf;
      pool.enqueue(std::bind(check, s));
    }
    return;
  }
  if (p == 0) {
    for (char c : to[-1]) {
      buf[p] = c;
      int add = 0;
      add += (c == '(' ? 1 : 0);
      add += (c == ')' ? -1 : 0);
      gen(p + 1, cnt + add);
    }
  } else if (p + 1 < len) {
    for (char c : to[buf[p - 1]]) {
      buf[p] = c;
      int add = 0;
      add += (c == '(' ? 1 : 0);
      add += (c == ')' ? -1 : 0);
      gen(p + 1, cnt + add);
    }
  } else {
    for (char c : to[buf[p - 1]]) {
      if (c == '(' || c == '|' || c == '&' || c == '!') continue;
      buf[p] = c;
      int add = 0;
      add += (c == '(' ? 1 : 0);
      add += (c == ')' ? -1 : 0);
      gen(p + 1, cnt + add);
    }
  }
}
void preprocess() {
  symbols = "xyz()!&|";
  to['x'] = "|&)";
  to['y'] = "|&)";
  to['z'] = "|&)";
  to['('] = "xyz(!";
  to[')'] = "|&)";
  to['!'] = "(xyz";
  to['&'] = "xyz(!";
  to['|'] = "xyz(!";
  to[-1] = "xyz(!";
  for (len = 1;; ++len) {
    gen();
    pool.wait();
    cout << len << " " << CNT << endl;
    if (CNT == N) {
      break;
    }
  }
  if (CNT == N) {
    cout << "AHTUNG" << endl;
  }
  for (int i = 0; i < N; ++i) {
    cout << "ans[" << i << "] = \"" << ans[i] << "\";\n";
  }
}
void prep_ans() {
  ans[0] = "!x&x";
  ans[1] = "!(x|y|z)";
  ans[2] = "!x&!y&z";
  ans[3] = "!x&!y";
  ans[4] = "!x&!z&y";
  ans[5] = "!x&!z";
  ans[6] = "!(!y&!z|x|y&z)";
  ans[7] = "!(x|y&z)";
  ans[8] = "!x&y&z";
  ans[9] = "!(!y&z|!z&y|x)";
  ans[10] = "!x&z";
  ans[11] = "!(!z&y|x)";
  ans[12] = "!x&y";
  ans[13] = "!(!y&z|x)";
  ans[14] = "!x&(y|z)";
  ans[15] = "!x";
  ans[16] = "!y&!z&x";
  ans[17] = "!y&!z";
  ans[18] = "!(!x&!z|x&z|y)";
  ans[19] = "!(x&z|y)";
  ans[20] = "!(!x&!y|x&y|z)";
  ans[21] = "!(x&y|z)";
  ans[22] = "!(!x&!y|x&y|z)|!x&!y&z";
  ans[23] = "!((x|y)&z|x&y)";
  ans[24] = "!x&y&z|!y&!z&x";
  ans[25] = "!x&y&z|!y&!z";
  ans[26] = "!x&z|!y&!z&x";
  ans[27] = "!x&z|!y&!z";
  ans[28] = "!x&y|!y&!z&x";
  ans[29] = "!x&y|!y&!z";
  ans[30] = "!x&(y|z)|!y&!z&x";
  ans[31] = "!x|!y&!z";
  ans[32] = "!y&x&z";
  ans[33] = "!(!x&z|!z&x|y)";
  ans[34] = "!y&z";
  ans[35] = "!(!z&x|y)";
  ans[36] = "!x&!z&y|!y&x&z";
  ans[37] = "!x&!z|!y&x&z";
  ans[38] = "!x&!z&y|!y&z";
  ans[39] = "!x&!z|!y&z";
  ans[40] = "!x&y&z|!y&x&z";
  ans[41] = "!(!x&z|!z&x|y)|!x&y&z";
  ans[42] = "!(x&y)&z";
  ans[43] = "!(!z&x|y)|!x&z";
  ans[44] = "!x&y|!y&x&z";
  ans[45] = "!(!y&z|x)|!y&x&z";
  ans[46] = "!x&y|!y&z";
  ans[47] = "!x|!y&z";
  ans[48] = "!y&x";
  ans[49] = "!(!x&z|y)";
  ans[50] = "!y&(x|z)";
  ans[51] = "!y";
  ans[52] = "!x&!z&y|!y&x";
  ans[53] = "!x&!z|!y&x";
  ans[54] = "!x&!z&y|!y&(x|z)";
  ans[55] = "!x&!z|!y";
  ans[56] = "!x&y&z|!y&x";
  ans[57] = "!(!x&z|y)|!x&y&z";
  ans[58] = "!x&z|!y&x";
  ans[59] = "!x&z|!y";
  ans[60] = "!x&y|!y&x";
  ans[61] = "!(!x&!y&z|x&y)";
  ans[62] = "!x&(y|z)|!y&x";
  ans[63] = "!x|!y";
  ans[64] = "!z&x&y";
  ans[65] = "!(!x&y|!y&x|z)";
  ans[66] = "!x&!y&z|!z&x&y";
  ans[67] = "!x&!y|!z&x&y";
  ans[68] = "!z&y";
  ans[69] = "!(!y&x|z)";
  ans[70] = "!x&!y&z|!z&y";
  ans[71] = "!x&!y|!z&y";
  ans[72] = "!x&y&z|!z&x&y";
  ans[73] = "!(!x&y|!y&x|z)|!x&y&z";
  ans[74] = "!x&z|!z&x&y";
  ans[75] = "!(!z&y|x)|!z&x&y";
  ans[76] = "!(x&z)&y";
  ans[77] = "!(!y&x|z)|!x&y";
  ans[78] = "!x&z|!z&y";
  ans[79] = "!x|!z&y";
  ans[80] = "!z&x";
  ans[81] = "!(!x&y|z)";
  ans[82] = "!x&!y&z|!z&x";
  ans[83] = "!x&!y|!z&x";
  ans[84] = "!z&(x|y)";
  ans[85] = "!z";
  ans[86] = "!x&!y&z|!z&(x|y)";
  ans[87] = "!x&!y|!z";
  ans[88] = "!x&y&z|!z&x";
  ans[89] = "!(!x&y|z)|!x&y&z";
  ans[90] = "!x&z|!z&x";
  ans[91] = "!(!x&!z&y|x&z)";
  ans[92] = "!x&y|!z&x";
  ans[93] = "!x&y|!z";
  ans[94] = "!x&(y|z)|!z&x";
  ans[95] = "!x|!z";
  ans[96] = "!y&x&z|!z&x&y";
  ans[97] = "!(!x&y|!y&x|z)|!y&x&z";
  ans[98] = "!y&z|!z&x&y";
  ans[99] = "!(!z&x|y)|!z&x&y";
  ans[100] = "!y&x&z|!z&y";
  ans[101] = "!(!y&x|z)|!y&x&z";
  ans[102] = "!y&z|!z&y";
  ans[103] = "!(!y&!z&x|y&z)";
  ans[104] = "!x&y&z|!y&x&z|!z&x&y";
  ans[105] = "!(!x&y|!y&x|z)|!x&y&z|!y&x&z";
  ans[106] = "!(x&y)&z|!z&x&y";
  ans[107] = "!(!z&x|y)|!x&z|!z&x&y";
  ans[108] = "!(x&z)&y|!y&x&z";
  ans[109] = "!(!y&x|z)|!x&y|!y&x&z";
  ans[110] = "!(x&y)&z|!z&y";
  ans[111] = "!x|!y&z|!z&y";
  ans[112] = "!(y&z)&x";
  ans[113] = "!(!x&y|z)|!y&x";
  ans[114] = "!y&z|!z&x";
  ans[115] = "!y|!z&x";
  ans[116] = "!y&x|!z&y";
  ans[117] = "!y&x|!z";
  ans[118] = "!y&(x|z)|!z&y";
  ans[119] = "!y|!z";
  ans[120] = "!(y&z)&x|!x&y&z";
  ans[121] = "!(!x&y|z)|!x&y&z|!y&x";
  ans[122] = "!(x&y)&z|!z&x";
  ans[123] = "!x&z|!y|!z&x";
  ans[124] = "!(x&z)&y|!y&x";
  ans[125] = "!x&y|!y&x|!z";
  ans[126] = "!x&y|!y&z|!z&x";
  ans[127] = "!(x&y&z)";
  ans[128] = "x&y&z";
  ans[129] = "!(x|y|z)|x&y&z";
  ans[130] = "!x&!y&z|x&y&z";
  ans[131] = "!x&!y|x&y&z";
  ans[132] = "!x&!z&y|x&y&z";
  ans[133] = "!x&!z|x&y&z";
  ans[134] = "!(!y&!z|x|y&z)|x&y&z";
  ans[135] = "!(x|y&z)|x&y&z";
  ans[136] = "y&z";
  ans[137] = "!(x|y|z)|y&z";
  ans[138] = "!x&z|y&z";
  ans[139] = "!x&!y|y&z";
  ans[140] = "!x&y|y&z";
  ans[141] = "!x&!z|y&z";
  ans[142] = "!x&(y|z)|y&z";
  ans[143] = "!x|y&z";
  ans[144] = "!y&!z&x|x&y&z";
  ans[145] = "!y&!z|x&y&z";
  ans[146] = "!(!x&!z|x&z|y)|x&y&z";
  ans[147] = "!(x&z|y)|x&y&z";
  ans[148] = "!(!x&!y|x&y|z)|x&y&z";
  ans[149] = "!(x&y|z)|x&y&z";
  ans[150] = "!(!x&!y|x&y|z)|!x&!y&z|x&y&z";
  ans[151] = "!((x|y)&z|x&y)|x&y&z";
  ans[152] = "!y&!z&x|y&z";
  ans[153] = "!y&!z|y&z";
  ans[154] = "!x&z|!y&!z&x|y&z";
  ans[155] = "!(x&z|y)|y&z";
  ans[156] = "!x&y|!y&!z&x|y&z";
  ans[157] = "!(x&y|z)|y&z";
  ans[158] = "!x&(y|z)|!y&!z&x|y&z";
  ans[159] = "!x|!y&!z|y&z";
  ans[160] = "x&z";
  ans[161] = "!(x|y|z)|x&z";
  ans[162] = "!y&z|x&z";
  ans[163] = "!x&!y|x&z";
  ans[164] = "!x&!z&y|x&z";
  ans[165] = "!x&!z|x&z";
  ans[166] = "!x&!z&y|!y&z|x&z";
  ans[167] = "!(x|y&z)|x&z";
  ans[168] = "(x|y)&z";
  ans[169] = "!(x|y|z)|(x|y)&z";
  ans[170] = "z";
  ans[171] = "!x&!y|z";
  ans[172] = "!x&y|x&z";
  ans[173] = "!(!y&z|x)|x&z";
  ans[174] = "!x&y|z";
  ans[175] = "!x|z";
  ans[176] = "!y&x|x&z";
  ans[177] = "!y&!z|x&z";
  ans[178] = "!y&(x|z)|x&z";
  ans[179] = "!y|x&z";
  ans[180] = "!x&!z&y|!y&x|x&z";
  ans[181] = "!(x&y|z)|x&z";
  ans[182] = "!x&!z&y|!y&(x|z)|x&z";
  ans[183] = "!x&!z|!y|x&z";
  ans[184] = "!y&x|y&z";
  ans[185] = "!(!x&z|y)|y&z";
  ans[186] = "!y&x|z";
  ans[187] = "!y|z";
  ans[188] = "!x&y|!y&x|x&z";
  ans[189] = "!x&!z|!y&x|y&z";
  ans[190] = "!x&y|!y&x|z";
  ans[191] = "!x|!y|z";
  ans[192] = "x&y";
  ans[193] = "!(x|y|z)|x&y";
  ans[194] = "!x&!y&z|x&y";
  ans[195] = "!x&!y|x&y";
  ans[196] = "!z&y|x&y";
  ans[197] = "!x&!z|x&y";
  ans[198] = "!x&!y&z|!z&y|x&y";
  ans[199] = "!(x|y&z)|x&y";
  ans[200] = "(x|z)&y";
  ans[201] = "!(x|y|z)|(x|z)&y";
  ans[202] = "!x&z|x&y";
  ans[203] = "!(!z&y|x)|x&y";
  ans[204] = "y";
  ans[205] = "!x&!z|y";
  ans[206] = "!x&z|y";
  ans[207] = "!x|y";
  ans[208] = "!z&x|x&y";
  ans[209] = "!y&!z|x&y";
  ans[210] = "!x&!y&z|!z&x|x&y";
  ans[211] = "!(x&z|y)|x&y";
  ans[212] = "!z&(x|y)|x&y";
  ans[213] = "!z|x&y";
  ans[214] = "!x&!y&z|!z&(x|y)|x&y";
  ans[215] = "!x&!y|!z|x&y";
  ans[216] = "!z&x|y&z";
  ans[217] = "!(!x&y|z)|y&z";
  ans[218] = "!x&z|!z&x|x&y";
  ans[219] = "!x&!y|!z&x|y&z";
  ans[220] = "!z&x|y";
  ans[221] = "!z|y";
  ans[222] = "!x&z|!z&x|y";
  ans[223] = "!x|!z|y";
  ans[224] = "(y|z)&x";
  ans[225] = "!(x|y|z)|(y|z)&x";
  ans[226] = "!y&z|x&y";
  ans[227] = "!(!z&x|y)|x&y";
  ans[228] = "!z&y|x&z";
  ans[229] = "!(!y&x|z)|x&z";
  ans[230] = "!y&z|!z&y|x&y";
  ans[231] = "!x&!y|!z&y|x&z";
  ans[232] = "(x|y)&z|x&y";
  ans[233] = "!(x|y|z)|(x|y)&z|x&y";
  ans[234] = "x&y|z";
  ans[235] = "!x&!y|x&y|z";
  ans[236] = "x&z|y";
  ans[237] = "!x&!z|x&z|y";
  ans[238] = "y|z";
  ans[239] = "!x|y|z";
  ans[240] = "x";
  ans[241] = "!y&!z|x";
  ans[242] = "!y&z|x";
  ans[243] = "!y|x";
  ans[244] = "!z&y|x";
  ans[245] = "!z|x";
  ans[246] = "!y&z|!z&y|x";
  ans[247] = "!y|!z|x";
  ans[248] = "x|y&z";
  ans[249] = "!y&!z|x|y&z";
  ans[250] = "x|z";
  ans[251] = "!y|x|z";
  ans[252] = "x|y";
  ans[253] = "!z|x|y";
  ans[254] = "x|y|z";
  ans[255] = "!x|x";
}
void solve() {
  prep_ans();
  int ma_l = 0;
  for (int i = 0; i < N; ++i) {
    ma_l = max(ma_l, (int)ans[i].length());
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int val = 0;
    for (int j = 0; j < 8; ++j) {
      if (s[j] == '1') {
        val |= (1 << j);
      }
    }
    cout << ans[val] << "\n";
  }
}
int main() {
  solve();
  return 0;
}
