Problem: 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.

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	static BufferedReader br;
    static StringTokenizer sc;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        //br = new BufferedReader(new FileReader("input.in"));
    	br = new BufferedReader(new InputStreamReader(System.in));
        //out = new PrintWriter("output.out");
    	out = new PrintWriter(System.out);
        sc = new StringTokenizer("");
        
        TaskD solver = new TaskD();
        solver.solve();
        
        br.close();
        out.close();
        //System.out.println("Finished");
    }    
    
    static class TaskD {
        public void solve() throws IOException {
        	int n = nxtInt();
        	
        	char[] num = new char[10];
        	for (int i = 0; i < 10; i++)
        		num[i] = 's';
        	
        	for (int i = 0; i < n; i++) {
        		String str = nxtTok();      		
        		
        		char[] arg = toBin(nxtInt());
        		
        		if (str.equals("&")) {
        			for (int j = 0; j < 10; j++) {
        				if (arg[j] == '0')
        					num[j] = '0';
        			}
        		}
        		else if (str.equals("|")) {
        			for (int j = 0; j < 10; j++) {
        				if (arg[j] == '1')
        					num[j] = '1';
        			}
        		}
        		else if (str.equals("^")) {
        			for (int j = 0; j < 10; j++) {
        				if (arg[j] == '1') {
        					if (num[j] == '1')
        						num[j] = '0';
        					else if (num[j] == '0')
        						num[j] = '1';
        					if (num[j] == 's')
        						num[j] = 'i';
        					else if (num[j] == 'i')
        						num[j] = 's';
        				}
        			}
        		}
        	}
        	
        	/***** XOR *****************/
        	boolean XOR = false;
        	int XORnumber = 0;
        	for (int i = 0; i < 10; i++) {
        		if (num [i] == 'i') {
        			XORnumber += Math.pow(2,  i);
        			XOR = true;
        		}
        	}
        	
        	/***** OR *****************/
        	boolean OR = false;
        	int ORnumber = 0;
        	for (int i = 0; i < 10; i++) {
        		if (num [i] == '1') {
        			ORnumber += Math.pow(2,  i);
        			OR = true;
        		}
        	}
        	
        	/***** AND *****************/
        	boolean AND = false;
        	int ANDnumber = 1023;
        	for (int i = 0; i < 10; i++) {
        		if (num [i] == '0') {
        			ANDnumber -= Math.pow(2,  i);
        			AND = true;
        		}
        	}
        	
        	int ops = 0;
        	if (XOR)
        		ops++;
        	if (OR)
        		ops++;
        	if (AND)
        		ops++;
        	
        	out.println(ops);
        	
        	if (XOR)
        		out.println("^ " + XORnumber);
        	if (OR)
        		out.println("| " + ORnumber);
        	if (AND)
        		out.println("& " + ANDnumber);
        }
        
        char[] toBin(int n) {
        	char[] num = new char[10];
        	
        	int index = 0;
        	
        	while (n > 0) {
        		if (n % 2 == 0)
        			num[index++] = '0';
        		else
        			num[index++] = '1';
        		
        		n = n / 2;
        	}
        	
        	for (int i = index; i < 10; i++)
        		num[i] = '0';
        	
        	return num;
        }

        class Trie {
            Node root;

            Trie() {
                root = new Node();
            }

            void add(long x) {

                Node cur = root;
                // int depth = 0;
                while (x > 0) {
                    int ls = (int)(x % 10);
                    x /= 10;
                    cur.cnt[ls]++;
                    if (cur.nodes[ls] == null)
                        cur.nodes[ls] = new Node();
                    cur = cur.nodes[ls];
                }
            }

            void sub(long x) {

                Node cur = root;
                while (x > 0) {
                    int ls = (int)(x % 10);
                    x /= 10;
                    cur.cnt[ls]--;
                    cur = cur.nodes[ls];
                }
            }

            long[] getcnt(long x) {

                int res = 0;
                int prev = 0;
                int depth = 0;
                Node cur = root;

                while (x > 0 && depth < 10) {
                    int ls = (int)(x % 10);
                    x /= 10;
                    res = cur.cnt[9 - ls];
                    if (res != 0) {
                        depth++;
                        prev = res;
                        cur = cur.nodes[9 - ls];
                    } else
                        break;
                }

                return new long[]{depth, prev};
            }

        }

        class Node {
            Node[] nodes;
            int[] cnt;

            Node() {
                nodes = new Node[10];
                cnt = new int[10];
            }

        }

    }

    static String nxtTok() throws IOException {
        while (!sc.hasMoreTokens()) {
            String s = br.readLine();
            
            if (s == null) {
                return null;
            }
            sc = new StringTokenizer(s.trim());
        }
        return sc.nextToken();
    }

    static int nxtInt() throws IOException {
        return Integer.parseInt(nxtTok());
    }

    static long nxtLng() throws IOException {
        return Long.parseLong(nxtTok());
    }

    static double nxtDbl() throws IOException {
        return Double.parseDouble(nxtTok());
    }

    static int[] nxtIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nxtInt();
        }
        return a;
    }

    static long[] nxtLngArr(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nxtLng();
        }
        return a;
    }

    static char[] nxtCharArr() throws IOException {
        return nxtTok().toCharArray();
    }
    
    static int getMin(int arr[], int count)
    {
    	int min = arr[0];
    	for (int i = 1; i < count; i++)
    		if (arr[i] < min)
    			min = arr[i];

    	return min;
    }

    static int getMax(int arr[], int count)
    {
    	int max = arr[0];
    	for (int i = 1; i < count; i++)
    		if (arr[i] > max)
    			max = arr[i];

    	return max;
    }

    static void sortAsc(int arr[], int count)
    {
        int temp;

        for (int i = 0; i < count - 1; i++)
        {
            for (int j = i + 1; j < count; j++)
            {
                if (arr[i] > arr[j])
                {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }

    static void sortDesc(int arr[], int count)
    {
        int temp;

        for (int i = 0; i < count - 1; i++)
        {
            for (int j = i + 1; j < count; j++)
            {
                if (arr[i] < arr[j])
                {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }
}