#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n;   string s;   vector<string> precalced = { !x&x ,                                !(x|y|z) ,                                !x&!y&z ,                                !x&!y ,                                !x&!z&y ,                                !x&!z ,                                !(!y&!z|x|y&z) ,                                !(x|y&z) ,                                !x&y&z ,                                !(!y&z|!z&y|x) ,                                !x&z ,                                !(!z&y|x) ,                                !x&y ,                                !(!y&z|x) ,                                !x&(y|z) ,                                !x ,                                !y&!z&x ,                                !y&!z ,                                !(!x&!z|x&z|y) ,                                !(x&z|y) ,                                !(!x&!y|x&y|z) ,                                !(x&y|z) ,                                !(!x&!y|x&y|z)|!x&!y&z ,                                !((x|y)&z|x&y) ,                                !x&y&z|!y&!z&x ,                                !x&y&z|!y&!z ,                                !x&z|!y&!z&x ,                                !x&z|!y&!z ,                                !x&y|!y&!z&x ,                                !x&y|!y&!z ,                                !x&(y|z)|!y&!z&x ,                                !x|!y&!z ,                                !y&x&z ,                                !(!x&z|!z&x|y) ,                                !y&z ,                                !(!z&x|y) ,                                !x&!z&y|!y&x&z ,                                !x&!z|!y&x&z ,                                !x&!z&y|!y&z ,                                !x&!z|!y&z ,                                !x&y&z|!y&x&z ,                                !(!x&z|!z&x|y)|!x&y&z ,                                !(x&y)&z ,                                !(!z&x|y)|!x&z ,                                !x&y|!y&x&z ,                                !(!y&z|x)|!y&x&z ,                                !x&y|!y&z ,                                !x|!y&z ,                                !y&x ,                                !(!x&z|y) ,                                !y&(x|z) ,                                !y ,                                !x&!z&y|!y&x ,                                !x&!z|!y&x ,                                !x&!z&y|!y&(x|z) ,                                !x&!z|!y ,                                !x&y&z|!y&x ,                                !(!x&z|y)|!x&y&z ,                                !x&z|!y&x ,                                !x&z|!y ,                                !x&y|!y&x ,                                !(!x&!y&z|x&y) ,                                !x&(y|z)|!y&x ,                                !x|!y ,                                !z&x&y ,                                !(!x&y|!y&x|z) ,                                !x&!y&z|!z&x&y ,                                !x&!y|!z&x&y ,                                !z&y ,                                !(!y&x|z) ,                                !x&!y&z|!z&y ,                                !x&!y|!z&y ,                                !x&y&z|!z&x&y ,                                !(!x&y|!y&x|z)|!x&y&z ,                                !x&z|!z&x&y ,                                !(!z&y|x)|!z&x&y ,                                !(x&z)&y ,                                !(!y&x|z)|!x&y ,                                !x&z|!z&y ,                                !x|!z&y ,                                !z&x ,                                !(!x&y|z) ,                                !x&!y&z|!z&x ,                                !x&!y|!z&x ,                                !z&(x|y) ,                                !z ,                                !x&!y&z|!z&(x|y) ,                                !x&!y|!z ,                                !x&y&z|!z&x ,                                !(!x&y|z)|!x&y&z ,                                !x&z|!z&x ,                                !(!x&!z&y|x&z) ,                                !x&y|!z&x ,                                !x&y|!z ,                                !x&(y|z)|!z&x ,                                !x|!z ,                                !y&x&z|!z&x&y ,                                !(!x&y|!y&x|z)|!y&x&z ,                                !y&z|!z&x&y ,                                !(!z&x|y)|!z&x&y ,                                !y&x&z|!z&y ,                                !(!y&x|z)|!y&x&z ,                                !y&z|!z&y ,                                !(!y&!z&x|y&z) ,                                !x&y&z|!y&x&z|!z&x&y ,                                !(!x&y|!y&x|z)|!x&y&z|!y&x&z ,                                !(x&y)&z|!z&x&y ,                                !(!z&x|y)|!x&z|!z&x&y ,                                !(x&z)&y|!y&x&z ,                                !(!y&x|z)|!x&y|!y&x&z ,                                !(x&y)&z|!z&y ,                                !x|!y&z|!z&y ,                                !(y&z)&x ,                                !(!x&y|z)|!y&x ,                                !y&z|!z&x ,                                !y|!z&x ,                                !y&x|!z&y ,                                !y&x|!z ,                                !y&(x|z)|!z&y ,                                !y|!z ,                                !(y&z)&x|!x&y&z ,                                !(!x&y|z)|!x&y&z|!y&x ,                                !(x&y)&z|!z&x ,                                !x&z|!y|!z&x ,                                !(x&z)&y|!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&z|x&y&z ,                                !x&!y|x&y&z ,                                !x&!z&y|x&y&z ,                                !x&!z|x&y&z ,                                !(!y&!z|x|y&z)|x&y&z ,                                !(x|y&z)|x&y&z ,                                y&z ,                                !(x|y|z)|y&z ,                                !x&z|y&z ,                                !x&!y|y&z ,                                !x&y|y&z ,                                !x&!z|y&z ,                                !x&(y|z)|y&z ,                                !x|y&z ,                                !y&!z&x|x&y&z ,                                !y&!z|x&y&z ,                                !(!x&!z|x&z|y)|x&y&z ,                                !(x&z|y)|x&y&z ,                                !(!x&!y|x&y|z)|x&y&z ,                                !(x&y|z)|x&y&z ,                                !(!x&!y|x&y|z)|!x&!y&z|x&y&z ,                                !((x|y)&z|x&y)|x&y&z ,                                !y&!z&x|y&z ,                                !y&!z|y&z ,                                !x&z|!y&!z&x|y&z ,                                !(x&z|y)|y&z ,                                !x&y|!y&!z&x|y&z ,                                !(x&y|z)|y&z ,                                !x&(y|z)|!y&!z&x|y&z ,                                !x|!y&!z|y&z ,                                x&z ,                                !(x|y|z)|x&z ,                                !y&z|x&z ,                                !x&!y|x&z ,                                !x&!z&y|x&z ,                                !x&!z|x&z ,                                !x&!z&y|!y&z|x&z ,                                !(x|y&z)|x&z ,                                (x|y)&z ,                                !(x|y|z)|(x|y)&z ,                                z ,                                !x&!y|z ,                                !x&y|x&z ,                                !(!y&z|x)|x&z ,                                !x&y|z ,                                !x|z ,                                !y&x|x&z ,                                !y&!z|x&z ,                                !y&(x|z)|x&z ,                                !y|x&z ,                                !x&!z&y|!y&x|x&z ,                                !(x&y|z)|x&z ,                                !x&!z&y|!y&(x|z)|x&z ,                                !x&!z|!y|x&z ,                                !y&x|y&z ,                                !(!x&z|y)|y&z ,                                !y&x|z ,                                !y|z ,                                !x&y|!y&x|x&z ,                                !x&!z|!y&x|y&z ,                                !x&y|!y&x|z ,                                !x|!y|z ,                                x&y ,                                !(x|y|z)|x&y ,                                !x&!y&z|x&y ,                                !x&!y|x&y ,                                !z&y|x&y ,                                !x&!z|x&y ,                                !x&!y&z|!z&y|x&y ,                                !(x|y&z)|x&y ,                                (x|z)&y ,                                !(x|y|z)|(x|z)&y ,                                !x&z|x&y ,                                !(!z&y|x)|x&y ,                                y ,                                !x&!z|y ,                                !x&z|y ,                                !x|y ,                                !z&x|x&y ,                                !y&!z|x&y ,                                !x&!y&z|!z&x|x&y ,                                !(x&z|y)|x&y ,                                !z&(x|y)|x&y ,                                !z|x&y ,                                !x&!y&z|!z&(x|y)|x&y ,                                !x&!y|!z|x&y ,                                !z&x|y&z ,                                !(!x&y|z)|y&z ,                                !x&z|!z&x|x&y ,                                !x&!y|!z&x|y&z ,                                !z&x|y ,                                !z|y ,                                !x&z|!z&x|y ,                                !x|!z|y ,                                (y|z)&x ,                                !(x|y|z)|(y|z)&x ,                                !y&z|x&y ,                                !(!z&x|y)|x&y ,                                !z&y|x&z ,                                !(!y&x|z)|x&z ,                                !y&z|!z&y|x&y ,                                !x&!y|!z&y|x&z ,                                (x|y)&z|x&y ,                                !(x|y|z)|(x|y)&z|x&y ,                                x&y|z ,                                !x&!y|x&y|z ,                                x&z|y ,                                !x&!z|x&z|y ,                                y|z ,                                !x|y|z ,                                x ,                                !y&!z|x ,                                !y&z|x ,                                !y|x ,                                !z&y|x ,                                !z|x ,                                !y&z|!z&y|x ,                                !y|!z|x ,                                x|y&z ,                                !y&!z|x|y&z ,                                x|z ,                                !y|x|z ,                                x|y ,                                !z|x|y ,                                x|y|z ,                                !x|x };   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s;       int x = 0;       for (int j = 0; j < 8; ++j) {         x += (s[j] -  0 ) * (1 << j);       }       cout << precalced[x] << endl;     }     return 0;   }