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.
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long fact(long long n) {
  long long f = 1;
  for (long long i = 1; i <= n; i++) f = (f * i) % mod;
  return f;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return (a * b) / gcd(a, b);
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
long long ModPow(long long a, long long b, long long M) {
  if (M == 1) return 0;
  a %= M;
  long long ans = 1, t = 1;
  while (t > 0 && t <= b) {
    if (t & b) {
      ans *= a;
      ans %= M;
    }
    t <<= 1;
    a *= a;
    a %= M;
  }
  return ans;
}
long long modInverse(long long n, long long p) { return ModPow(n, p - 2, p); }
long long nCrModP(long long n, long long r, long long p) {
  if (n < r) return 0;
  if (r == 0) return 1;
  long long fac[n + 1];
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
int aux(vector<int>& a, int p, int r) {
  int ma = a[p], ind = p;
  for (int i = p; i <= r; i++) {
    if (a[i] > ma) {
      ma = a[i];
      ind = i;
    }
  }
  return ind;
}
void MAX(vector<int>& a, int p, int r, int d, vector<int>& ans) {
  if (p <= r) {
    int q = aux(a, p, r);
    ans[q] = d;
    MAX(a, p, q - 1, d + 1, ans);
    MAX(a, q + 1, r, d + 1, ans);
  }
}
struct Comparator {
  bool operator()(const pair<int, int>& value, const int& key) {
    return (value.first < key);
  }
  bool operator()(const int& key, const pair<int, int>& value) {
    return (key < value.first);
  }
};
bool revsort(long long a, long long b) { return a > b; }
bool check(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    return false;
  else
    return true;
}
void v_out(vector<int>& ans) {
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << "\n";
}
void solve() {
  int n;
  cin >> n;
  char ch;
  int op;
  vector<vector<int> > r(10, vector<int>(2));
  for (long long i = 0; i < 10; i++) {
    r[i][0] = 0;
    r[i][1] = 1;
  }
  for (long long i = 0; i < n; i++) {
    cin >> ch >> op;
    if (ch == '|') {
      for (long long j = 0; j < 10; j++) {
        if ((op & (1 << j)) != 0) {
          r[j][0] = 1;
          r[j][1] = 1;
        }
      }
    } else if (ch == '^') {
      for (long long j = 0; j < 10; j++) {
        if ((op & (1 << j)) != 0) {
          r[j][0] = 1 - r[j][0];
          r[j][1] = 1 - r[j][1];
        }
      }
    } else {
      for (long long j = 0; j < 10; j++) {
        if ((op & (1 << j)) == 0) {
          r[j][0] = 0;
          r[j][1] = 0;
        }
      }
    }
  }
  int a = 0, b = 1023, c = 0;
  for (long long i = 0; i < 10; i++) {
    if (r[i][0] == 1 && r[i][1] == 1)
      a = (a ^ (1 << i));
    else if (r[i][0] == 0 && r[i][1] == 0)
      b = (b ^ (1 << i));
    else if (r[i][0] == 1 && r[i][1] == 0)
      c = (c ^ (1 << i));
  }
  cout << 3 << "\n";
  cout << "| " << a << "\n";
  cout << "& " << b << "\n";
  cout << "^ " << c << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
