1
& 0
 1
^ 123
 10
^ 218
& 150
| 935
& 61
| 588
& 897
| 411
| 584
^ 800
| 704
 3
& 1
& 3
& 5
 1
| 123
 1
^ 0
 1
| 1023
 3
& 242
^ 506
^ 522
 10
^ 160
& 1021
& 510
^ 470
& 1022
& 251
& 760
& 1016
| 772
| 515
 1
& 1023
 1
| 0
 2
| 56
^ 875
 1
^ 1023
 2
| 999
^ 689
 3
^ 125
^ 377
& 1019
 1
& 123

3
& 0
| 0
^ 0
 3
& 1023
| 0
^ 123
 3
& 763
| 763
^ 0
 3
& 1
| 0
^ 0
 3
& 1023
| 123
^ 0
 3
& 1023
| 0
^ 0
 3
& 1023
| 1023
^ 0
 3
& 1010
| 768
^ 240
 2
| 775
^ 112
 3
& 1023
| 0
^ 0
 3
& 1023
| 0
^ 0
 3
& 983
| 16
^ 835
 3
& 1023
| 0
^ 1023
 3
& 350
| 326
^ 16
 3
& 1019
| 0
^ 256
 3
& 123
| 0
^ 0

#include <bits/stdc++.h>
using namespace std;
void operate(pair<char, long long int> &a, pair<char, long long int> b) {
  pair<char, long long int> ans;
  if (b.first == '&') {
    a = make_pair(a.first, a.second & b.second);
  } else if (b.first == '|') {
    a = make_pair(a.first, a.second | b.second);
  } else {
    a = make_pair(a.first, a.second ^ b.second);
  }
}
void solve() {
  long long int n;
  cin >> n;
  long long int pren = -1;
  char pre = 'o';
  vector<pair<char, long long int>> ans;
  for (long long int i = 0; i < n; ++i) {
    char c;
    long long int x;
    cin >> c >> x;
    if (ans.size() < 3) {
      if (!(c == '|' && x == 1) && !(c == '^' && x == 0)) {
        ans.emplace_back(c, x);
      }
    } else {
      for (long long int j = 0; j < 3; ++j) {
        if (ans[i].first == c) {
          pair<char, long long int> val;
          val.first = ans[i].first;
          val.second = ans[i].second;
          ans.erase(ans.begin() + i);
          long long int k = i;
          for (long long int l = i; l < ans.size(); ++l) {
            operate(val, ans[l]);
          }
          operate(val, make_pair(c, x));
          ans.push_back(val);
          break;
        }
      }
    }
  }
  for (auto i = static_cast<long long int>(ans.size() - 1); i > 0; --i) {
    if (ans[i].first == ans[i - 1].first) {
      operate(ans[i - 1], ans[i]);
      ans.erase(ans.begin() + i);
    }
  }
  if (ans.size() == 1) {
    if (ans[0].first == '|' && ans[0].second == 0) {
      cout << 0;
    } else if (ans[0].first == '^' && ans[0].second == 0) {
      cout << 0;
    } else {
      cout << 1 << endl;
      cout << ans[0].first << " " << ans[0].second << endl;
    }
    return;
  }
  cout << ans.size() << endl;
  for (auto &an : ans) {
    cout << an.first << " " << an.second << endl;
  }
}
int main() {
  solve();
  return 0;
}
