Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.

In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.

Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.

Input

The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.

Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.

Output

Output an integer k (0 ≤ k ≤ 5) — the length of your program.

Next k lines must contain commands in the same format as in the input.

Examples

Input

3
| 3
^ 2
| 1


Output

2
| 3
^ 2


Input

3
&amp; 1
&amp; 3
&amp; 5


Output

1
&amp; 1


Input

3
^ 1
^ 2
^ 3


Output

0

Note

You can read about bitwise operations in <https://en.wikipedia.org/wiki/Bitwise_operation>.

Second sample:

Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
//        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }


    void solve() throws IOException {
        int n = readInt();
        char[] ops = new char[n];
        int[] num = new int[n];
        for (int i = 0; i < n; i++) {
            ops[i] = readString().charAt(0);
            num[i] = readInt();
        }
        int[][] has = new int[2][BITS];
        for (int bit = 0; bit < BITS; bit++) {
            for (int was = 0; was < 2; was++) {
                int cur = was;
                for (int op = 0; op < n; op++) {
                    int b = (num[op] >> bit) & 1;
                    if (ops[op] == '|') {
                        cur |= b;
                    } else if (ops[op] == '&') {
                        cur &= b;
                    } else {
                        cur ^= b;
                    }
                }
                has[was][bit] = cur;
            }
        }
        brut(0, new char[5], new int[5], has);
    }

    int BITS = 10;

    void brut(int cnt, char[] a, int[] values, int[][] target) {
        boolean fail = false;
        Arrays.fill(values, 0);
        for (int bit = 0; bit < BITS; bit++) {
            int res = findBit(a, cnt, target, bit);
            if (res == -1) {
                fail = true;
                break;
            }
            for (int i = 0; i < cnt; i++) {
                int b = (res >> i) & 1;
                values[i] |= b << bit;
            }
        }
        if (!fail) {
            out.println(cnt);
            for (int i = 0; i < cnt; i++) {
                out.println(a[i] + " " + values[i]);
            }
            out.flush();
            out.close();
            System.exit(0);
        }
        if (cnt == 5) return;

        for (char op : ops) {
            a[cnt] = op;
            brut(cnt + 1, a, values, target);
        }
    }

    char[] ops = {'|', '&', '^'};

    int findBit(char[] a, int cnt, int[][] target, int bit) {
        int max = 1 << cnt;
        for (int vals = 0; vals < max; vals++) {
            boolean fail = false;
            for (int was = 0; was < 2; was++) {
                int cur = was;
                for (int j = 0; j < cnt; j++) {
                    int b = (vals >> j) & 1;
                    cur = apply(cur, b, a[j]);
                }
                if (cur != target[was][bit]) {
                    fail = true;
                    break;
                }
            }
            if (!fail) return vals;
        }
        return -1;
    }

    int apply(int was, int bit, char op) {
        if (op == '|') return was | bit;
        if (op == '&') return was & bit;
        return was ^ bit;
    }

}