#include <bits/stdc++.h>   using namespace std;   string f[300], t[300], e[300];   char s[20];   int n;   bool cmp(string& a, string b) {     if (a ==   ) return 1;     return a.size() == b.size() ? a > b : a.size() > b.size();   }   int main() {     f[240] =  x ;     f[204] =  y ;     f[170] =  z ;     while (1) {       bool ok = 0;       for (int i = 0; i < 256; i++)         if (e[i] !=    && cmp(f[i],  (  + e[i] +  ) )) {           ok = 1;           f[i] =  (  + e[i] +  ) ;         }       for (int i = 0; i < 256; i++)         if (f[i] !=    && cmp(f[i ^ ((1 << 8) - 1)],  !  + f[i])) {           f[i ^ ((1 << 8) - 1)] =  !  + f[i];           ok = 1;         }       for (int i = 0; i < 256; i++)         if (f[i] !=    && cmp(t[i], f[i])) {           t[i] = f[i];           ok = 1;         }       for (int i = 0; i < 256; i++)         if (t[i] !=   )           for (int j = 0; j < 256; j++)             if (t[j] !=    && cmp(t[i & j], t[i] +  &  + t[j])) {               t[i & j] = t[i] +  &  + t[j];               ok = 1;             }       for (int i = 0; i < 256; i++)         if (t[i] !=    && cmp(e[i], t[i])) {           e[i] = t[i];           ok = 1;         }       for (int i = 0; i < 256; i++)         if (e[i] !=   )           for (int j = 0; j < 256; j++)             if (e[j] !=    && cmp(e[i | j], e[i] +  |  + e[j])) {               e[i | j] = e[i] +  |  + e[j];               ok = 1;             }       if (!ok) break;     }     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s);       int c = 0;       for (int j = 0; j < 8; j++) c |= ((s[j] -  0 ) << j);       cout << e[c] << endl;     }     return 0;   }   