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;
using ll = long long int;

const size_t max_string_length = 100000;
template<class T> struct is_cstr: std::false_type {}; template<int N> struct is_cstr<char[N]> : std::true_type {};
template<typename T> constexpr string formcomm(const T& a) {if constexpr (is_same_v<T, int> || is_same_v<T, size_t>) return "%d"; else if constexpr (is_same_v<T, long long int>) return "%lld"; else if constexpr (is_same_v<T, short int>) return "%hd"; else if constexpr (is_same_v<T, unsigned int>) return "%u"; else if constexpr (is_same_v<T, unsigned long long int>) return "%llu"; else if constexpr (is_same_v<T, unsigned short int>) return "%hu"; else if constexpr (is_same_v<T, char>) return "%c"; else {printf("Type %s non prévu\n", typeid(a).name()); terminate();}}
template<typename T> constexpr string formout(const T& a) {if constexpr (is_same_v<T, float>) return "%.16f"; else if constexpr (is_same_v<T, double>) return "%.16lf"; else if constexpr (is_same_v<T, long double>) return "%.16Lf"; else if constexpr (is_same_v<T, string>) return "%s"; else if constexpr (is_cstr<T>::value) return "%s"; else return formcomm(a);}
template<typename T> const T& addout(const T& a) {return a;} const char* addout(const string& a) {return a.c_str();} 
template<typename... Ts> void out(Ts&&... ts) {printf((formout(ts)+...).c_str(), addout(ts)...);}
template<typename It> void outs(It a, It b, string mid = " ", string fin = "\n") {if (a != b) {out(*a); ++a; for (; a != b; ++a) out (mid, *a);} out(fin);}
template<typename T> void outs(const T& l, string mid = " ", string fin = "\n") {outs(l.begin(), l.end(), mid, fin);}
template<typename T> constexpr string formin(const T& a) {if constexpr (is_same_v<T, float>) return "%f"; else if constexpr (is_same_v<T, double>) return "%lf"; else if constexpr (is_same_v<T, long double>) return "%Lf"; else if constexpr (is_same_v<T, string>) return "%s"; else if constexpr (is_cstr<T>::value) return "%s"; else return formcomm(a);}
template<typename T> constexpr int nstring(const T& a) {if constexpr (is_same_v<T, string>) return 1; else return 0;}
template<typename T> T* addin(T& a, char*& buf, string**& as) {return &a;} char* addin(string& a, char*& buf, string**& as) {char* ob = buf;buf+=max_string_length+1;*as = &a;++as;return ob;} 
template<typename... Ts> void in(Ts&&... ts) {int ns=(nstring(ts)+...);string* as[max(ns,1)];char buf[1+(max_string_length+1)*ns];char* b=buf;string** c=as;
 scanf((formin(ts)+...).c_str(), addin(ts, b, c)...); while (c > as) {--c; b-=max_string_length+1; **c = string(b);}}
template<typename It> void ins(It a, It b) {for (; a != b; ++a) in (*a);} template<typename T> void ins(T& l) {ins(l.begin(), l.end());} 
void inl(char* s) {scanf("%[^\n]", s);} void inl(string& s) {char buf[max_string_length+1]; inl(buf); s = string(buf);}

void simplify(list<pair<int, int> >& op)
{
 bool change;
 do
 {
  change = false;
  auto it1 = op.begin();
  auto it2 = it1; ++it2;
  while (it2 != op.end())
  {
   if (it1->first == it2->first)
   {
    switch (it1->first)
    {
     case 0: it1->second ^= it2->second; break;
     case 1: it1->second |= it2->second; break;
     case 2: it1->second &= it2->second; break;
    }
    it2 = op.erase(it2);
   }
   else if (it1->first == 2 && it2->first == 1)
   {
    swap(*it1, *it2);
    it2->second |= it1->second;
    ++it1; ++it2;
    change = true;
   }
   else if (it1->first == 1 && it2->first == 0)
   {
    swap(*it1, *it2);
    op.insert(it2, pair<int, int>(2, 1023 & ~it2->second));
    it2->second &= 1023 & ~it1->second;
    ++it1; 
    change = true;
   }
   else if (it1->first == 2 && it2->first == 0)
   {
    swap(*it1, *it2);
    op.insert(it2, pair<int, int>(2, it2->second));
    it1->second = 1023 & ~it1->second;
    it2->second = 1023 & ~it2->second;
    it2->second &= it1->second;
    ++it1; 
    change = true;
   }
   else {++it1; ++it2;}
  }
 } while (change);
 

}
	
int main()
{
 int n;
 in(n);
 list<pair<int, int> > op;
 for (int i = 0; i < n; ++i)
 {
  string s; int u;
  in(s, u);
  switch (s[0])
  {
   case '^': op.push_back(pair<int, int>(0, u)); break;
   case '|': op.push_back(pair<int, int>(1, u)); break;
   case '&': op.push_back(pair<int, int>(2, u)); break;
  }
  simplify(op);
 }
 out(op.size(), "\n");
 for (auto& [u, v]: op)
 {
  switch (u)
  {
   case 0: out("^ "); break;
   case 1: out("| "); break;
   case 2: out("& "); break;
  }
  out(v, "\n");
 }
 return 0;
}
