#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;
typedef unsigned uint;
string num(uint n){
    stringstream ss;
    ss << n;
    return ss.str();
}
string negative(string expr){
    return "(~" + expr + ")";
}
string operate(string expr1, string expr2, char op){
    return "(" + expr1 + op + expr2 +")";
}
int main(){
    int N;
    while(cin >> N){
        vector<uint> x(N);
        vector<uint> y(N);
        REP(i, N) cin >> x[i] >> y[i];
        string ans = "0";
        for(int t = 0, s = 1; t < 8; t++, s<<=1){
            // add
            vector<uint> b(N); // lowest bit
            REP(i, N) b[i] = (y[i] >> t) & 1;

            if(b == vector<uint>(N, 0)) continue;

            map<vector<uint>, string> e_dict;
            for(uint dx = 0; dx < 256; dx++){
                vector<uint> fb(N);

                //constant
                REP(i, N) fb[i] = dx >> t & 1;
                if(!e_dict.count(fb)) e_dict[fb] = num(dx);

                if(dx == 0){
                    REP(i, N) fb[i] = x[i] >> t & 1;
                    if(!e_dict.count(fb)) e_dict[fb] = "x";
                    continue;
                }

                // add
                REP(i, N) fb[i] = (x[i] + dx) >> t & 1;
                if(!e_dict.count(fb)) e_dict[fb] = operate("x", num(dx), '+');

                // sub
                REP(i, N) fb[i] = (x[i] - dx) >> t & 1;
                if(!e_dict.count(fb)) e_dict[fb] = operate("x", num(dx), '-');

                // mul
                REP(i, N) fb[i] = (x[i] * dx) >> t & 1;
                if(!e_dict.count(fb)) e_dict[fb] = operate("x", num(dx), '*');
            }
            bool update = true;
            while(update && !e_dict.count(b)){
                update = false;
                map<vector<uint>, string> new_dict;
                for(auto& p : e_dict)
                for(auto& q : e_dict){
                    vector<uint> fb(N);
                    REP(i, N) fb[i] = (p.first[i] & q.first[i]);
                    if(!new_dict.count(fb)){
                        update = true;
                        new_dict[fb] = operate(p.second, q.second, '&');
                    }
                    REP(i, N) fb[i] = (p.first[i] | q.first[i]);
                    if(!new_dict.count(fb)){
                        update = true;
                        new_dict[fb] = operate(p.second, q.second, '|');
                    }
                    REP(i, N) fb[i] = (p.first[i] ^ q.first[i]);
                    if(!new_dict.count(fb)){
                        update = true;
                        new_dict[fb] = operate(p.second, q.second, '^');
                    }
                }
                for(auto& p : e_dict){
                    vector<uint> fb(N);
                    REP(i, N) fb[i] = ~p.first[i];
                    if(new_dict.count(fb)){
                        update = true;
                        new_dict[fb] = negative(p.second);
                    }
                }
                if(update) e_dict.swap(new_dict);
            }
            assert(e_dict.count(b));
            ans = operate(ans, operate(e_dict[b], num(s), '&'), '|');
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1344