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·10^5) — 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 x_{i} 0 ≤ x_{i} ≤ 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
& 1
& 3
& 5

Output
1
& 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.

Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Constructive algorithms
Skill types: Bit manipulation

Starter code:

Solutions:
import sys
input = sys.stdin.readline
n = int(input())
com = []
for _ in range(n):
	l = input().split()
	com.append((l[0], int(l[1])))
(AND, OR, XOR) = ([], [], [])
for i in range(10):
	res1 = 0
	res2 = 1
	for (s, n) in com:
		b = n >> i & 1
		if s == '&':
			res1 &= b
			res2 &= b
		elif s == '|':
			res1 |= b
			res2 |= b
		elif s == '^':
			res1 ^= b
			res2 ^= b
	if (res1, res2) == (0, 0):
		AND.append(i)
	elif (res1, res2) == (1, 1):
		OR.append(i)
	elif (res1, res2) == (1, 0):
		XOR.append(i)
AND_n = 0
for i in range(10):
	if i not in AND:
		AND_n += 2 ** i
OR_n = 0
for i in OR:
	OR_n += 2 ** i
XOR_n = 0
for i in XOR:
	XOR_n += 2 ** i
print(3)
print('&', AND_n)
print('|', OR_n)
print('^', XOR_n)


from operator import __or__, __and__, __xor__
from sys import stdin, stdout
(n, b, c) = (int(stdin.readline()), 0, 1023)
m = {'|': __or__, '&': __and__, '^': __xor__}
for i in range(n):
	(t, v) = [i for i in stdin.readline().split()]
	b = m[t](b, int(v))
	c = m[t](c, int(v))
(x, o, a) = (0, 0, 1023)
for i in range(10):
	if b >> i & 1 and c >> i & 1:
		o |= 1 << i
	elif not b >> i & 1 and (not c >> i & 1):
		a -= 1 << i
	elif b >> i & 1 and (not c >> i & 1):
		x |= 1 << i
stdout.write('3\n| ' + str(o) + '\n^ ' + str(x) + '\n& ' + str(a))


n = int(input())
a = 0
b = 1023
for i in range(n):
	(s, d) = input().split()
	d = int(d)
	if s == '|':
		a |= d
		b |= d
	elif s == '&':
		a &= d
		b &= d
	elif s == '^':
		a ^= d
		b ^= d
ans = []
ans.append(('|', 1023 ^ a ^ b))
ans.append(('^', 1023 ^ b))
print(len(ans))
for i in range(len(ans)):
	print(ans[i][0] + ' ' + str(ans[i][1]))


n = int(input())
(a, b) = (1023, 0)
for _ in range(n):
	(c, d) = input().split()
	d = int(d)
	if c == '|':
		(a, b) = (a | d, b | d)
	elif c == '&':
		(a, b) = (a & d, b & d)
	elif c == '^':
		(a, b) = (a ^ d, b ^ d)
print('2\n| {}\n^ {}'.format(a ^ b ^ 1023, a ^ 1023))


def execute(prg, n):
	for (op, x) in prg:
		if op == '|':
			n |= x
		elif op == '&':
			n &= x
		elif op == '^':
			n ^= x
	return n
n = int(input())
prg = []
for i in range(n):
	(op, x) = map(str, input().split())
	x = int(x)
	prg.append((op, x))
zeroes = execute(prg, 0)
ones = execute(prg, 1023)
(orx, andx, xorx) = (0, 0, 0)
for i in range(10):
	bit = 1 << i
	if zeroes & bit == 0 and ones & bit == 0:
		pass
	elif zeroes & bit == 0 and ones & bit != 0:
		andx |= bit
	elif zeroes & bit != 0 and ones & bit == 0:
		xorx |= bit
		andx |= bit
	elif zeroes & bit != 0 and ones & bit != 0:
		orx |= bit
		andx |= bit
print(3)
print('|', orx)
print('&', andx)
print('^', xorx)


n = int(input())
mask_ans1 = 1023
mask_ans2 = 0
for i in range(n):
	(com, x) = input().split()
	x = int(x)
	if com == '&':
		mask_ans1 &= x
		mask_ans2 &= x
	elif com == '|':
		mask_ans1 |= x
		mask_ans2 |= x
	elif com == '^':
		mask_ans1 ^= x
		mask_ans2 ^= x
ans11 = 1023 & ~mask_ans2
ans12 = mask_ans1
ans13 = 1023 & (1023 ^ mask_ans1)
ans1 = 1023 ^ 1023 & ~mask_ans1 & ans11
ans2 = mask_ans2 & ans12
ans3 = 1023 & (mask_ans2 ^ 0) & ans13
lst = []
cnt = 3
if ans1 == 1023:
	cnt -= 1
if ans2 == 0:
	cnt -= 1
if ans3 == 0:
	cnt -= 1
print(cnt)
if ans1 != 1023:
	print('&', ans1)
if ans2 != 0:
	print('|', ans2)
if ans3 != 0:
	print('^', ans3)


from sys import stdin, stdout
n = int(stdin.readline())
a = list()
y = 0
for i in range(n):
	(oper, x) = stdin.readline().split()
	x = int(x)
	a.append((oper, x))
	if oper == '&':
		y &= x
	elif oper == '|':
		y |= x
	elif oper == '^':
		y ^= x
AND = (1 << 10) - 1
OR = 0
XOR = 0
for k in range(10):
	cur = 1 << k
	for comm in a:
		(oper, x) = comm
		if oper == '&':
			cur &= x
		elif oper == '|':
			cur |= x
		elif oper == '^':
			cur ^= x
	res0 = y & 1 << k
	res1 = cur & 1 << k
	if not res0 and (not res1):
		AND ^= 1 << k
	elif not res0 and res1:
		pass
	elif res0 and (not res1):
		XOR ^= 1 << k
	else:
		OR ^= 1 << k
print(3)
print('& ', AND)
print('| ', OR)
print('^ ', XOR)


n = int(input())
zero = 0
ones = 1023
for _ in range(n):
	(op, num) = input().split()
	num = int(num)
	if op == '&':
		zero &= num
		ones &= num
	elif op == '|':
		zero |= num
		ones |= num
	else:
		zero ^= num
		ones ^= num
and_bits = 0
or_bits = 0
xor_bits = 0
for i in range(10):
	z = zero >> i & 1
	o = ones >> i & 1
	if z == 0 and o == 0:
		and_bits |= 0 << i
		or_bits |= 0 << i
		xor_bits |= 0 << i
	elif z == 0 and o == 1:
		and_bits |= 1 << i
		or_bits |= 0 << i
		xor_bits |= 0 << i
	elif z == 1 and o == 0:
		and_bits |= 1 << i
		or_bits |= 0 << i
		xor_bits |= 1 << i
	else:
		and_bits |= 1 << i
		or_bits |= 1 << i
		xor_bits |= 0 << i
print(3)
print('& {}'.format(and_bits))
print('| {}'.format(or_bits))
print('^ {}'.format(xor_bits))


import sys, math

def main():
	ops = getops(sys.stdin)
	n1 = 0
	n2 = 1023
	for op in ops:
		n1 = calc(op, n1)
		n2 = calc(op, n2)
	if n2 == 1023 and n1 == 0:
		print(0)
	else:
		and_ = 1023
		or_ = 0
		xor_ = 0
		for i in range(10):
			b1 = n1 % 2
			b2 = n2 % 2
			n1 = n1 // 2
			n2 = n2 // 2
			if b1 == 1 and b2 == 1:
				or_ = or_ | 2 ** i
			elif b1 == 1 and b2 == 0:
				xor_ = xor_ | 2 ** i
			elif b1 == 0 and b2 == 0:
				and_ = and_ - 2 ** i
		print(3)
		print('&', and_)
		print('|', or_)
		print('^', xor_)

def getops(fh):
	n = int(fh.readline())
	ops = []
	for i in range(n):
		(opi, numi) = fh.readline().split()
		numi = int(numi)
		ops.append((opi, numi))
	return ops

def calc(op, res):
	(opi, numi) = op
	if opi == '|':
		res = res | numi
	elif opi == '&':
		res = res & numi
	else:
		res = res ^ numi
	return res
main()


n = int(input())
queries = list((input().split() for _ in range(n)))
(a, b) = (0, (1 << 10) - 1)
for (c, x) in queries:
	x = int(x)
	if c == '|':
		(a, b) = (a | x, b | x)
	elif c == '&':
		(a, b) = (a & x, b & x)
	elif c == '^':
		(a, b) = (a ^ x, b ^ x)
(x, y, z) = (0, (1 << 10) - 1, 0)
for i in range(10):
	a_i = a >> i & 1
	b_i = b >> i & 1
	if a_i and b_i:
		x |= 1 << i
	if not a_i and (not b_i):
		y ^= 1 << i
	if a_i and (not b_i):
		z ^= 1 << i
print(3)
print('|', x)
print('&', y)
print('^', z)


from sys import *
d = {'|': lambda t: t | k, '&': lambda t: t & k, '^': lambda t: t ^ k}
(a, b) = (1023, 0)
for i in range(int(input())):
	(s, q) = stdin.readline().split()
	k = int(q)
	a = d[s](a)
	b = d[s](b)
t = [2]
for u in range(1024):
	for v in range(1024):
		if 1023 ^ v == a and u ^ v == b:
			print('2\n|', u, '\n^', v)
			exit()


(a, b) = (0, 1023)
n = int(input())
for i in range(n):
	(l, r) = input().split(' ')
	r = int(r)
	if l == '|':
		(a, b) = (a | r, b | r)
	elif l == '&':
		(a, b) = (a & r, b & r)
	elif l == '^':
		(a, b) = (a ^ r, b ^ r)
print('3')
print('&', 1023 & a | b)
print('^', a & (1023 ^ b))
print('|', a & b)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
first = 0
last = 1023
for _ in range(n):
	i = input().split()
	if i[0] == '|':
		first = first | int(i[1])
		last = last | int(i[1])
	elif i[0] == '&':
		first = first & int(i[1])
		last = last & int(i[1])
	else:
		first = first ^ int(i[1])
		last = last ^ int(i[1])
a = bin(first).replace('0b', '')
b = bin(last).replace('0b', '')
a = '0' * (10 - len(a)) + a
b = '0' * (10 - len(b)) + b
a = list(map(int, list(a)))
b = list(map(int, list(b)))
_xor = []
_or = []
for i in range(10):
	if a[i] == b[i]:
		if a[i] == 0:
			_xor.append(1)
			_or.append(1)
		else:
			_xor.append(0)
			_or.append(1)
	elif a[i] == 1:
		_xor.append(1)
		_or.append(0)
	else:
		_xor.append(0)
		_or.append(0)
x = y = 0
for i in range(10):
	y += _xor[i] * 2 ** (9 - i)
	x += _or[i] * 2 ** (9 - i)
print(2)
print('| ', x)
print('^ ', y)


f = lambda t: t | k if s == '|' else t & k if s == '&' else t ^ k
(a, b) = (1023, 0)
for i in range(int(input())):
	(s, k) = input().split()
	k = int(k)
	(a, b) = (f(a), f(b))
print('2\n|', b ^ a ^ 1023, '\n^', 1023 ^ a)


from sys import stdin, stdout

class Solve:

	def __init__(self):
		R = stdin.readline
		W = stdout.write
		n = int(input())
		(z, o) = (0, 1023)
		for i in range(n):
			(op, x) = R().split()
			x = int(x)
			if op == '|':
				z |= x
				o |= x
			elif op == '&':
				z &= x
				o &= x
			elif op == '^':
				z ^= x
				o ^= x
		ans = {'^': 0, '|': 0, '&': 1023}
		for b in range(10):
			bit = 1 << b
			bitz = z & bit
			bito = o & bit
			if bool(bitz) and (not bool(bito)):
				ans['^'] |= bit
			elif bool(bitz) and bool(bito):
				ans['|'] |= bit
			elif not bool(bitz) and (not bool(bito)):
				ans['&'] ^= bit
		W('3\n')
		for op in ans:
			print(op, ans[op])

def main():
	s = Solve()
main()


(a, b) = (0, 1023)
n = int(input())
for i in range(n):
	cmd = input()
	(c, x) = cmd.split()
	x = int(x)
	if c == '|':
		(a, b) = (a | x, b | x)
	elif c == '&':
		(a, b) = (a & x, b & x)
	else:
		(a, b) = (a ^ x, b ^ x)
x = 0
y = 1023
z = 0
for i in range(10):
	a_i = a >> i & 1
	b_i = b >> i & 1
	if a_i and b_i:
		x |= 1 << i
	if not a_i and (not b_i):
		y ^= 1 << i
	if a_i and (not b_i):
		z ^= 1 << i
print('3\n| {}\n& {}\n^ {}'.format(x, y, z))


import sys
n = int(sys.stdin.readline())
(zero_model, one_model) = (0, (1 << 10) - 1)
commands = []
for i in range(n):
	(c, k) = sys.stdin.readline()[:-1].split()
	k = int(k)
	commands.append((c, k))

def process(n, commands):
	for comm in commands:
		(c, k) = comm
		if c == '|':
			n |= k
		elif c == '^':
			n ^= k
		elif c == '&':
			n &= k
	return n
zero_model = process(0, commands)
one_model = process((1 << 10) - 1, commands)
set_zero = (1 << 10) - 1
flip = 0
set_one = 0
for i in range(10):
	bz = zero_model & 1 << i
	bo = one_model & 1 << i
	if bz >= 1 and bo == 0:
		flip |= 1 << i
	elif bz >= 1 and bo >= 1:
		set_one |= 1 << i
	elif bz == 0 and bo == 0:
		set_zero &= ~(1 << i)
ans = [('&', set_zero), ('^', flip), ('|', set_one)]
print(len(ans))
for comm in ans:
	print(*comm)


n = int(input())
bits0 = [0] * 10
bits1 = [1] * 10
b0 = 0
b1 = 1023
fname = ['&', '|', '^']
f = [[[0, 0], [0, 1]], [[0, 1], [1, 1]], [[0, 1], [1, 0]]]
for i in range(n):
	s = input()
	e = str(bin(int(s[2:])))
	d = int(s[2:])
	if s[0] == '^':
		b0 = b0 ^ d
		b1 = b1 ^ d
	elif s[0] == '|':
		b0 = b0 | d
		b1 = b1 | d
	elif s[0] == '&':
		b0 = b0 & d
		b1 = b1 & d
for j in range(10):
	bits0[9 - j] = b0 % 2
	b0 = b0 // 2
	bits1[9 - j] = b1 % 2
	b1 = b1 // 2
c = [[0] * 10, [0] * 10, [1] * 10]
for j in range(10):
	if bits0[j] == bits1[j]:
		if bits0[j] == 0:
			c[2][j] = 0
		else:
			c[1][j] = 1
	elif bits0[j] == 1:
		c[0][j] = 1
print(3)
(c0, c1, c2) = [0, 0, 0]
for i in range(10):
	c0 += c[0][i] * 2 ** (9 - i)
	c1 += c[1][i] * 2 ** (9 - i)
	c2 += c[2][i] * 2 ** (9 - i)
print('^ ' + str(c0))
print('| ' + str(c1))
print('& ' + str(c2))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
n = int(input())
com = []
for _ in range(n):
	l = input().split()
	com.append((l[0], int(l[1])))
(AND, OR, XOR) = ([], [], [])
for i in range(10):
	res1 = 0
	res2 = 1
	for (s, n) in com:
		b = n >> i & 1
		if s == '&':
			res1 &= b
			res2 &= b
		elif s == '|':
			res1 |= b
			res2 |= b
		elif s == '^':
			res1 ^= b
			res2 ^= b
	if (res1, res2) == (0, 0):
		AND.append(i)
	elif (res1, res2) == (1, 1):
		OR.append(i)
	elif (res1, res2) == (1, 0):
		XOR.append(i)
AND_n = 0
for i in range(10):
	if i not in AND:
		AND_n += 2 ** i
OR_n = 0
for i in OR:
	OR_n += 2 ** i
XOR_n = 0
for i in XOR:
	XOR_n += 2 ** i
print(3)
print('&', AND_n)
print('|', OR_n)
print('^', XOR_n)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = []
for i in range(n):
	l.append(input().split())
x = 89
l1 = [[0, 1] for i in range(10)]
for i in l:
	a = bin(int(i[1])).lstrip('0b')
	if len(a) != 10:
		a = '0' * (10 - len(a)) + a
	if i[0] == '|':
		for j in range(10):
			l1[j][0] = l1[j][0] | int(a[j])
			l1[j][1] = l1[j][1] | int(a[j])
	elif i[0] == '&':
		for j in range(10):
			l1[j][0] = l1[j][0] & int(a[j])
			l1[j][1] = l1[j][1] & int(a[j])
	else:
		for j in range(10):
			l1[j][0] = l1[j][0] ^ int(a[j])
			l1[j][1] = l1[j][1] ^ int(a[j])
a2 = 1023
o = 0
x = 0
for i in range(10):
	if l1[i][0] == 1 and l1[i][1] == 1:
		o += 2 ** (9 - i)
	elif l1[i][0] == 0 and l1[i][1] == 0:
		a2 -= 2 ** (9 - i)
	elif l1[i][0] == 1 and l1[i][1] == 0:
		x += 2 ** (9 - i)
print(3)
print('&', a2)
print('|', o)
print('^', x)


from sys import stdin
BITCOUNT = 10
xONES = (1 << 10) - 1
xZEROS = 0
n = int(stdin.readline())
for i in range(n):
	(op, num) = stdin.readline().split()
	num = int(num)
	if op == '&':
		xONES &= num
		xZEROS &= num
	elif op == '|':
		xONES |= num
		xZEROS |= num
	else:
		xONES ^= num
		xZEROS ^= num
andmask = 0
xormask = 0
mask = 1
for i in range(BITCOUNT):
	ONESbit = xONES >> i & 1
	ZEROSbit = xZEROS >> i & 1
	if ONESbit == 1 and ZEROSbit == 0:
		andmask += mask
	elif ONESbit == 0 and ZEROSbit == 1:
		andmask += mask
		xormask += mask
	elif ONESbit == 1 and ZEROSbit == 1:
		xormask += mask
	mask *= 2
print(2)
print('& {}'.format(andmask))
print('^ {}'.format(xormask))


def solve():
	n = int(input())
	a = 0
	b = 1023
	for i in range(n):
		(op, k) = input().split()
		k = int(k)
		if op == '|':
			a |= k
			b |= k
		if op == '^':
			a ^= k
			b ^= k
		if op == '&':
			a &= k
			b &= k
	p = 1
	print(3)
	aa = a
	bb = b
	ans = 0
	for i in range(10):
		if aa % 2 == 1 and bb % 2 == 0:
			ans += p
		p *= 2
		aa //= 2
		bb //= 2
	print('^', ans)
	p = 1
	ans = 1023
	aa = a
	bb = b
	for i in range(10):
		if aa % 2 == 0 and bb % 2 == 0:
			ans -= p
		p *= 2
		aa //= 2
		bb //= 2
	print('&', ans)
	p = 1
	ans = 0
	aa = a
	bb = b
	for i in range(10):
		if aa % 2 == 1 and bb % 2 == 1:
			ans += p
		p *= 2
		aa //= 2
		bb //= 2
	print('|', ans)
	return

def main():
	t = 1
	for _ in range(t):
		solve()
main()


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
import math
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n = int(input())
a = 0
b = 1023
for i in range(n):
	(c, k) = input().strip().split(' ')
	k = int(k)
	if c == '|':
		a |= k
		b |= k
	elif c == '^':
		a ^= k
		b ^= k
	elif c == '&':
		a &= k
		b &= k
OR = 0
XOR = 0
for i in range(10):
	x = 1 << i
	if a & x and b & x:
		OR |= x
	if a & x and ~b & x:
		XOR |= x
	if ~a & x and ~b & x:
		OR |= x
		XOR |= x
print('2')
print('|', OR)
print('^', XOR)


def n2b(n):
	b = bin(n)[2:]
	r = 10 - len(b)
	return list('0' * r + b)

def b2n(b):
	return int(''.join(b), 2)

def dump_encoded(s):
	ops = []
	op = '&'
	b = ''
	for i in range(10):
		if s[i] == '0':
			b += '0'
		else:
			b += '1'
	ops.append((op, b2n(b)))
	op = '|'
	b = ''
	for i in range(10):
		if s[i] == '1':
			b += '1'
		else:
			b += '0'
	ops.append((op, b2n(b)))
	op = '^'
	b = ''
	for i in range(10):
		if s[i] == 'y':
			b += '1'
		else:
			b += '0'
	ops.append((op, b2n(b)))
	print(len(ops))
	for (op, n) in ops:
		print(op, n)
m = int(input())
ops = []
for i in range(m):
	(op, n) = input().split(' ')
	n = int(n)
	ops.append((op, n))
s = 1023
for i in range(len(ops)):
	(op, n) = ops[i]
	if op == '&':
		s = s & n
	elif op == '|':
		s = s | n
	elif op == '^':
		s = s ^ n
b1 = n2b(s)
s = 0
for i in range(len(ops)):
	(op, n) = ops[i]
	if op == '&':
		s = s & n
	elif op == '|':
		s = s | n
	elif op == '^':
		s = s ^ n
b2 = n2b(s)
g = ''
for k in range(10):
	if b1[k] == b2[k]:
		if b1[k] == '0':
			g += '0'
		else:
			g += '1'
	elif b1[k] == '0':
		g += 'y'
	else:
		g += 'x'
dump_encoded(g)


from sys import stdin
n = int(input())
s = []
c = 0
c1 = 1023
for i in range(n):
	(st, num) = map(str, stdin.readline().split())
	num = int(num)
	if st == '&':
		c &= num
		c1 &= num
	elif st == '|':
		c |= num
		c1 |= num
	else:
		c ^= num
		c1 ^= num
xornum = ~c1
ornum = ~(c ^ c1)
xornum &= 1023
ornum &= 1023
print(2)
print('|', ornum)
print('^', xornum)


def simu(P, i):
	for (c, x) in P:
		if c == '&':
			i &= x
		elif c == '|':
			i |= x
		else:
			i ^= x
	return i

def simpl(P):
	(out0, out1) = (simu(P, 0), simu(P, 1023))
	(A, O, X) = (1023, 0, 0)
	for i in range(10):
		B01 = (out0 >> i & 1, out1 >> i & 1)
		if B01 == (0, 0):
			A ^= 1 << i
		elif B01 == (1, 0):
			X |= 1 << i
		elif B01 == (1, 1):
			O |= 1 << i
	return (A, O, X)

def main():
	n = int(input())
	P = []
	for _ in range(n):
		(c, x) = input().split()
		P.append((c, int(x)))
	(A, O, X) = simpl(P)
	print(3)
	print('&', A)
	print('|', O)
	print('^', X)
main()


from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def run_program(n, program):
	for (op, a) in program:
		assert op in '&|^'
		if op == '&':
			n = n & a
		if op == '|':
			n = n | a
		if op == '^':
			n = n ^ a
	return n
N = int(input())
q = 1023
r = 0
original_program = []
for _ in range(N):
	(op, s) = input().split(' ')
	s = int(s)
	original_program += [(op, s)]
	if op == '&':
		q = q & s
		r = r & s
	elif op == '^':
		r = r ^ s
	elif op == '|':
		(q, r) = (q ^ q & s, r ^ s ^ r & s)
	else:
		assert False
final_program = [('&', q), ('^', r)]
print(2)
print(f'& {q}')
print(f'^ {r}')


import sys
input = sys.stdin.readline
n = int(input())
start1 = 0
start2 = 1023
for _ in range(n):
	(a, b) = map(str, input().split())
	b = int(b)
	if a == '|':
		start1 = b | start1
		start2 = b | start2
	elif a == '^':
		start1 = b ^ start1
		start2 = b ^ start2
	else:
		start1 = b & start1
		start2 = b & start2
ans = []
ands = 1023
xors = 0
ors = 0
for i in range(10):
	k = 1 << i
	if start1 & k and start2 & k:
		ors += k
	elif start1 & k and (not start2 & k):
		xors += k
	elif not start1 & k and (not start2 & k):
		ands -= k
print(3)
print('&', ands)
print('^', xors)
print('|', ors)


import sys
n = int(sys.stdin.readline())
zero_result = 0
ones_result = 1023
while n > 0:
	[op, val] = sys.stdin.readline().split(' ')
	val = int(val)
	n -= 1
	if op == '&':
		zero_result = zero_result & val
		ones_result = ones_result & val
	elif op == '|':
		zero_result = zero_result | val
		ones_result = ones_result | val
	elif op == '^':
		zero_result = zero_result ^ val
		ones_result = ones_result ^ val
	else:
		pass
and_bin = [1 for i in range(10)]
or_bin = [0 for i in range(10)]
xor_bin = [0 for i in range(10)]
for i in range(10):
	j = 9 - i
	zero_digit = zero_result >> j
	ones_digit = ones_result >> j
	zero_result = zero_result - zero_digit * 2 ** j
	ones_result = ones_result - ones_digit * 2 ** j
	if zero_digit == 0 and ones_digit == 0:
		and_bin[j] = 0
	elif zero_digit == 1 and ones_digit == 0:
		xor_bin[j] = 1
	elif zero_digit == 1 and ones_digit == 1:
		or_bin[j] = 1
and_int = 0
xor_int = 0
or_int = 0
for i in range(10):
	and_int += and_bin[i] * 2 ** i
	or_int += or_bin[i] * 2 ** i
	xor_int += xor_bin[i] * 2 ** i
print(3)
print('&', and_int)
print('|', or_int)
print('^', xor_int)


n = int(input())
A = 1023
B = 0
a = 1023
b = 0
print(4)
for i in range(n):
	s = str(input())
	if s[0] == '&':
		a = a & int(s[2:])
		b = b & int(s[2:])
	elif s[0] == '|':
		a = a | int(s[2:])
		b = b | int(s[2:])
	elif s[0] == '^':
		a = a ^ int(s[2:])
		b = b ^ int(s[2:])
Al = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Bl = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
al = [0 for kk in range(10)]
bl = [0 for kk in range(10)]
for i in range(9, -1, -1):
	if a >= 2 ** i:
		al[i] = 1
		a -= 2 ** i
for i in range(9, -1, -1):
	if b >= 2 ** i:
		bl[i] = 1
		b -= 2 ** i
And = []
Or = []
Xor = []
for i in range(10):
	if al[i] == 0 and bl[i] == 0:
		And.append(i)
	if al[i] == 0 and bl[i] == 1:
		Xor.append(i)
	if al[i] == 1 and bl[i] == 1:
		Or.append(i)
r = 0
for i in range(10):
	if i not in And:
		r += 2 ** i
print('&', r)
r = 0
if Xor == []:
	print('^ 0')
	print('^ 0')
elif Xor == [0]:
	print('^ 0')
	print('& 1')
else:
	r = 2 ** (max(Xor) + 1) - 1
	print('^', r)
	r = 0
	for i in range(max(Xor) + 1):
		if i not in Xor:
			r += 2 ** i
	print('^', r)
r = 0
for i in range(10):
	if i in Or:
		r += 2 ** i
print('|', r)


from math import *
n = int(input())
x = 0
y = 1023
for i in range(n):
	gg = input().split()
	if gg[0] == '&':
		x &= int(gg[1])
		y &= int(gg[1])
	if gg[0] == '|':
		x |= int(gg[1])
		y |= int(gg[1])
	if gg[0] == '^':
		x ^= int(gg[1])
		y ^= int(gg[1])
print(3)
print('|', x & y)
print('&', x | y)
print('^', x & (y ^ 1023))


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
P = []
for i in range(N):
	P.append(input().split())
N = 2
S = [0, 1023]
T = [v for v in S]
for i in range(N):
	for (p, v) in P:
		v = int(v)
		if p == '^':
			T[i] ^= v
		elif p == '|':
			T[i] |= v
		else:
			T[i] &= v
(a, b, c) = (0, 0, 0)
for i in range(10, -1, -1):
	a <<= 1
	b <<= 1
	c <<= 1
	c |= 1
	if all([v >> i & 1 == 1 for v in T]):
		b |= 1
	elif all([v >> i & 1 == 0 for v in T]):
		c >>= 1
		c <<= 1
	elif all([S[j] >> i & 1 != T[j] >> i & 1 for j in range(N)]):
		a |= 1
print(3)
print('^', a)
print('|', b)
print('&', c)


q = int(input())

def calc(f):
	ret1 = 0
	ret2 = 1023
	for op in f:
		if op[0] == '&':
			ret1 &= op[1]
			ret2 &= op[1]
		elif op[0] == '|':
			ret1 |= op[1]
			ret2 |= op[1]
		elif op[0] == '^':
			ret1 ^= op[1]
			ret2 ^= op[1]
	return (ret1, ret2)
f = list()
for i in range(q):
	(oper, n) = input().split()
	n = int(n)
	f.append((oper, n))
(op0, op1) = calc(f)
op0 = ('0000000000' + bin(op0)[2:])[-10:][::-1]
op1 = ('0000000000' + bin(op1)[2:])[-10:][::-1]
o = 0
x = 0
for i in range(10):
	if op0[i] == '1' and op1[i] == '1':
		o += 2 ** i
	elif op0[i] == '1' and op1[i] == '0':
		x += 2 ** i
	elif op0[i] == '0' and op1[i] == '0':
		o += 2 ** i
		x += 2 ** i
print(2)
print('| ' + str(o))
print('^ ' + str(x))


z = 0
o = 1023
n = int(input())
for i in range(n):
	(a, b) = input().split()
	b = int(b)
	if a == '&':
		z = z & b
		o = o & b
	if a == '^':
		z = z ^ b
		o = o ^ b
	if a == '|':
		z = z | b
		o = o | b
z = '{:010b}'.format(z)
o = '{:010b}'.format(o)
an = 0
r = 0
xo = 0
pw = 512
for i in range(10):
	an += pw
	if o[i] == '0' and z[i] == '0':
		an -= pw
	if o[i] == '1' and z[i] == '1':
		r += pw
	if o[i] == '0' and z[i] == '1':
		xo += pw
	pw //= 2
print(3)
print('&', an)
print('|', r)
print('^', xo)


from operator import and_, or_, xor
n = int(input())
ops = []
for _ in range(n):
	s = input().split()
	ops.append([s[0], int(s[1])])
samples = [0, 1023]
ans = []
tab = {'^': xor, '&': and_, '|': or_}
for s in samples:
	for op in ops:
		s = tab[op[0]](s, op[1])
	ans.append(s)
(diz, con, xxor) = ('', '', '')
for (b1, b2) in zip('{0:0>10b}'.format(ans[0]), '{0:0>10b}'.format(ans[1])):
	if b1 == '1' and b2 == '0':
		diz += '0'
		con += '1'
		xxor += '1'
	elif b1 == '0' and b2 == '1':
		diz += '0'
		con += '1'
		xxor += '0'
	elif b1 == '1' and b2 == '1':
		diz += '1'
		con += '1'
		xxor += '0'
	elif b1 == '0' and b2 == '0':
		diz += '0'
		con += '0'
		xxor += '0'
print(3)
print('|', int(diz, 2))
print('&', int(con, 2))
print('^', int(xxor, 2))


import sys
import heapq
import math
from enum import Enum

class Status:
	UNTOUCHED = 1
	FLIPPED = 2
	ONE = 3
	ZERO = 4
bits = [Status.UNTOUCHED] * 10
lines = sys.stdin.read().splitlines()
n = int(lines[0])
andNum = 1023
orNum = 0
xorNum = 0
for i in range(1, n + 1):
	(operation, num) = lines[i].split(' ')
	num = int(num)
	if operation == '|':
		andNum = andNum | num
		orNum = orNum | num
		xorNum = xorNum & (orNum ^ 1023)
	elif operation == '&':
		andNum = andNum & num
		orNum = orNum & num
		xorNum = xorNum & num
	else:
		oldAndNum = andNum
		oldOrNum = orNum
		andNum = andNum ^ (orNum | andNum ^ 1023) & num
		orNum = orNum ^ (oldAndNum ^ 1023 | orNum) & num
		xorNum = xorNum ^ oldAndNum & (oldOrNum ^ 1023) & num
print(3)
print('& ' + str(andNum))
print('| ' + str(orNum))
print('^ ' + str(xorNum))


import sys
input = sys.stdin.readline
n = int(input())
a = 1023
b = 0
for _ in range(n):
	(s, num) = input().rstrip().split()
	num = int(num)
	if s == '|':
		(a, b) = (a | num, b | num)
	elif s == '&':
		(a, b) = (a & num, b & num)
	else:
		(a, b) = (a ^ num, b ^ num)
print('2\n| {}\n^ {}'.format(a ^ b ^ 1023, a ^ 1023))


from __future__ import print_function
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import log2, ceil, sqrt
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
bit = [-2] * 10

def solve(op, bitIdx, isSet):
	if op == '|' and isSet:
		bit[bitIdx] = 1
	elif op == '^' and isSet:
		if bit[bitIdx] in (-2, 2):
			bit[bitIdx] *= -1
		else:
			bit[bitIdx] ^= 1
	elif op == '&' and isSet == 0:
		bit[bitIdx] = 0
for _ in range(n):
	(op, arg) = gl()
	arg = int(arg)
	idx = 0
	for idx in range(10):
		solve(op, idx, 1 if arg & 1 << idx else 0)
val = [0] * 3
for i in range(10):
	if bit[i] >= 0:
		val[bit[i]] += 1 << i
val[0] ^= 1023
print(3)
print('|', val[1])
print('^', val[2])
print('&', val[0])


n = int(input())
m = 2 ** 10 - 1
a = 0
b = m
for _ in range(n):
	(op, l) = input().split()
	v = int(l)
	if op == '|':
		a |= v
		b |= v
	elif op == '&':
		a &= v
		b &= v
	else:
		a ^= v
		b ^= v
print(3)
print('&', a | b)
print('|', a & b)
print('^', a & (b ^ m))


import sys
n = int(sys.stdin.readline())
stat = [0] * 10
for i in range(n):
	(op, arg) = sys.stdin.readline().split()
	arg = int(arg)
	if op == '&':
		for j in range(10):
			if arg & 1 << j == 0:
				stat[j] = 3
	elif op == '|':
		for j in range(10):
			if arg & 1 << j > 0:
				stat[j] = 2
	else:
		for j in range(10):
			if arg & 1 << j > 0:
				stat[j] ^= 1
print('3')
orarg = 0
for i in range(10):
	if stat[i] == 2:
		orarg |= 1 << i
print('| ' + str(orarg))
andarg = (1 << 10) - 1
for i in range(10):
	if stat[i] == 3:
		andarg ^= 1 << i
print('& ' + str(andarg))
xorarg = 0
for i in range(10):
	if stat[i] == 1:
		xorarg += 1 << i
print('^ ' + str(xorarg))


import sys
import io, os
input = sys.stdin.readline
n = int(input())
X = [-1] * 10
for i in range(n):
	(c, x) = map(str, input().split())
	x = int(x)
	if c == '&':
		for j in range(10):
			if not x & 1 << j:
				X[j] = 0
	elif c == '|':
		for j in range(10):
			if x & 1 << j:
				X[j] = 1
	else:
		for j in range(10):
			if x & 1 << j:
				if X[j] == -1:
					X[j] = 2
				elif X[j] == 2:
					X[j] = -1
				elif X[j] == 1:
					X[j] = 0
				else:
					X[j] = 1
(a, b, c) = (0, 0, 0)
for i in range(10):
	if X[i] == -1:
		a |= 1 << i
	elif X[i] == 2:
		a |= 1 << i
		c |= 1 << i
	elif X[i] == 1:
		b |= 1 << i
print(3)
print('&', a)
print('|', b)
print('^', c)


import sys
input = sys.stdin.readline
import copy
from math import *
n = int(input())
a = [-1 for i in range(10)]
for i in range(n):
	(p, q) = input().split()
	qq = bin(int(q))[2:]
	q = list((10 - len(qq)) * '0' + qq)
	if p == '|':
		for i in range(9, -1, -1):
			if q[i] == '1':
				a[i] = 1
	if p == '&':
		for i in range(9, -1, -1):
			if q[i] == '0':
				a[i] = 0
	if p == '^':
		for i in range(9, -1, -1):
			if q[i] == '1' and (a[i] == 0 or a[i] == 1):
				a[i] ^= 1
			elif q[i] == '1':
				if a[i] == -1:
					a[i] = -2
				else:
					a[i] = -1
c = 0
for i in range(10):
	if a[i] == -2:
		c += 2 ** (10 - i - 1)
print(3)
print('^', c)
v = list('0' * 10)
for i in range(10):
	if a[i] == 1:
		v[i] = '1'
print('|', int(''.join(v), 2))
u = list('1' * 10)
for i in range(10):
	if a[i] == 0:
		u[i] = '0'
print('&', int(''.join(u), 2))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
a = int(input())
bits = ['r' for i in range(10)]
temp = ['r' for i in range(10)]
for i in range(a):
	(x, y) = input().split()
	y = int(y)
	n = bin(y)
	n = n[2:]
	ans = ''
	for i in range(10 - len(n)):
		ans += '0'
	ans = ans + n
	if x == '|':
		for i in range(len(bits)):
			if ans[i] == '1':
				temp[i] = '1'
	if x == '&':
		for i in range(len(bits)):
			if ans[i] == '0':
				temp[i] = '0'
	if x == '^':
		for i in range(len(bits)):
			if temp[i] == '0' and ans[i] == '1' or (temp[i] == '1' and ans[i] == '0'):
				temp[i] = '1'
			elif temp[i] == ans[i] and (temp[i] == '0' or temp[i] == '1'):
				temp[i] = '0'
			elif ans[i] == '1':
				if temp[i] == 'r':
					temp[i] = 'rb'
				else:
					temp[i] = 'r'
ad = ['0' for i in range(10)]
xor = ['0' for i in range(10)]
nd = ['1' for i in range(10)]
for i in range(len(temp)):
	if temp[i] == '1':
		ad[i] = '1'
		nd[i] = '1'
		xor[i] = '0'
	elif temp[i] == '0':
		nd[i] = '0'
		ad[i] = '0'
		xor[i] = '1'
	elif temp[i] == 'rb':
		xor[i] = '1'
		ad[i] = '0'
		nd[i] = '1'
	else:
		xor[i] = '0'
		ad[i] = '0'
		nd[i] = '1'
ad = int(''.join(map(str, ad)), 2)
nd = int(''.join(map(str, nd)), 2)
xor = int(''.join(map(str, xor)), 2)
print(3)
print('^', xor)
print('&', nd)
print('|', ad)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
arr = [2] * 10
for _ in range(ii()):
	(s, v) = input().split()
	v = int(v)
	if s == b'|':
		for i in range(10):
			if v & 2 ** i:
				arr[i] = 1
	elif s == b'^':
		for i in range(10):
			if v & 2 ** i:
				arr[i] ^= 1
	elif s == b'&':
		for i in range(10):
			if not v & 2 ** i:
				arr[i] = 0
	else:
		print(s)
print(3)
x = o = a = 0
for i in range(10):
	if arr[i] == 3:
		x += 2 ** i
	elif arr[i] == 0:
		a += 2 ** i
	elif arr[i] == 1:
		o += 2 ** i
print('|', o)
print('^', x)
print('&', 2 ** 10 - a - 1)


from sys import stdin, stdout
from operator import __or__, __and__, __xor__
oper = {'&': __and__, '|': __or__, '^': __xor__}
n = int(stdin.readline())
a = 0
b = (1 << 10) - 1
for i in range(n):
	(op, x) = stdin.readline().split()
	x = int(x)
	a = oper[op](a, x)
	b = oper[op](b, x)
AND = (1 << 10) - 1
OR = 0
XOR = 0
for k in range(10):
	res0 = a & 1 << k
	res1 = b & 1 << k
	if not res0 and (not res1):
		AND ^= 1 << k
	elif not res0 and res1:
		pass
	elif res0 and (not res1):
		XOR ^= 1 << k
	else:
		OR ^= 1 << k
print(3)
print('& ', AND)
print('| ', OR)
print('^ ', XOR)


n = int(input())
i0 = 0
i1 = 1023
for i in range(n):
	(cmd, ks) = input().split()
	k = int(ks)
	if cmd == '&':
		i0 &= k
		i1 &= k
	elif cmd == '|':
		i0 |= k
		i1 |= k
	elif cmd == '^':
		i0 ^= k
		i1 ^= k
xor_i = 0
or_i = 0
and_i = 1023
for i in range(10):
	b0 = i0 >> i & 1
	b1 = i1 >> i & 1
	if b0 == 1 and b1 == 0:
		xor_i |= 1 << i
	if b0 == 1 and b1 == 1:
		or_i |= 1 << i
	if b0 == 0 and b1 == 0:
		and_i &= ~(1 << i)
shortened = []
if xor_i != 0:
	shortened.append('^ ' + str(xor_i))
if or_i != 0:
	shortened.append('| ' + str(or_i))
if and_i != 1023:
	shortened.append('& ' + str(and_i))
print(len(shortened))
print('\n'.join(shortened))


import queue

def readTuple():
	return input().split()

def readInts():
	return tuple(map(int, readTuple()))

def to_int(x):
	x = x[::-1]
	res = 0
	for i in x:
		res <<= 1
		res |= i
	return res

def solve():
	res = ['X'] * 10
	(n,) = readInts()
	(a, b) = (0, 1023)
	for _ in range(n):
		(char, num) = readTuple()
		num = int(num)
		if char == '|':
			a |= num
			b |= num
		if char == '&':
			a &= num
			b &= num
		if char == '^':
			a ^= num
			b ^= num
	(XOR, OR) = ([], [])
	for i in range(10):
		b1 = a & 1 << i
		b2 = b & 1 << i
		if b1 and b2:
			OR.append(1)
			XOR.append(0)
		if not b1 and (not b2):
			OR.append(1)
			XOR.append(1)
		if b1 and (not b2):
			OR.append(0)
			XOR.append(1)
		if not b1 and b2:
			OR.append(0)
			XOR.append(0)
	print(2)
	print(f'| {to_int(OR)}')
	print(f'^ {to_int(XOR)}')
solve()


from sys import stdin
input = stdin.readline

def check(x, b, c):
	if b == '|':
		if c == '1':
			return 1
		else:
			return x
	elif b == '&':
		if c == '1':
			return x
		else:
			return 0
	elif c == '1':
		if x == 3:
			return 2
		if x == 2:
			return 3
		if x == 1:
			return 0
		if x == 0:
			return 1
	else:
		return x
n = int(input())
a = []
op = []
for i in range(n):
	(sign, x) = map(str, input().split())
	op.append(sign)
	a.append(bin(int(x))[2:].rjust(10, '0'))
And = 1023
Or = 0
Xor = 0
for i in range(10):
	result = 2
	for j in range(n):
		result = check(result, op[j], a[j][i])
	if result == 0:
		And -= 1 << 9 - i
	elif result == 1:
		Or += 1 << 9 - i
	elif result == 3:
		Xor += 1 << 9 - i
print(3)
print('&', And)
print('|', Or)
print('^', Xor)


from sys import stdin
data = stdin.readlines()
remain = -10
invert = -20
m = [remain] * 10
for (i, st) in enumerate(data):
	if i == 0:
		continue
	(op, x) = st.strip().split()
	x = int(x)
	for j in range(10):
		bit = x % 2
		if op == '&' and bit == 0:
			m[j] = 0
		elif op == '|' and bit == 1:
			m[j] = 1
		elif op == '^' and bit == 1:
			if m[j] == 0:
				m[j] = 1
			elif m[j] == 1:
				m[j] = 0
			elif m[j] == remain:
				m[j] = invert
			elif m[j] == invert:
				m[j] = remain
		x = x // 2
print(3)
and_const = 0
for (i, v) in enumerate(m):
	if v != 0:
		and_const += 2 ** i
or_const = 0
for (i, v) in enumerate(m):
	if v == 1:
		or_const += 2 ** i
xor_const = 0
for (i, v) in enumerate(m):
	if v == invert:
		xor_const += 2 ** i
print('&', and_const)
print('|', or_const)
print('^', xor_const)


def fun(n1, o, n2):
	if o == '|':
		return n1 | n2
	elif o == '&':
		return n1 & n2
	else:
		return n1 ^ n2

def fun2(n):
	l = [0 for i in range(10)]
	for i in range(9, -1, -1):
		if 1 << i <= n:
			l[i] = 1
			n -= 1 << i
	return l
n = int(input())
a = 0
b = 1023
for i in range(n):
	(o, n2) = input().split()
	n2 = int(n2)
	a = fun(a, o, n2)
	b = fun(b, o, n2)
l1 = fun2(a)
l2 = fun2(b)
a = 0
b = 0
for i in range(10):
	if l1[i] == 1 and l2[i] == 1:
		a += 1 << i
	elif l1[i] == 0 and l2[i] == 0:
		a += 1 << i
		b += 1 << i
	elif l1[i] == 1 and l2[i] == 0:
		b += 1 << i
print(2)
print('|', a)
print('^', b)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def ctd(chr):
	return ord(chr) - ord('a')
mod = 998244353
INF = float('inf')

def main():
	n = N()
	(zero, one) = (0, 1023)
	for _ in range(n):
		(op, n) = input().split()
		n = int(n)
		if op == '|':
			zero |= n
			one |= n
		elif op == '^':
			zero ^= n
			one ^= n
		else:
			zero &= n
			one &= n
	res = [0, 0, 0]
	for i in range(10):
		tg = 1 << i
		(pzero, pone) = (zero >> i & 1, one >> i & 1)
		if pzero == 0 and pone == 0:
			res[1] += tg
			res[2] += tg
		elif pone == 1 and pzero == 1:
			res[1] += tg
		elif pone == 0 and pzero == 1:
			res[2] += tg
	rec = ['&', '|', '^']
	print(3 - res.count(0))
	for i in range(3):
		if res[i] != 0:
			print(rec[i], res[i])
main()