In a far away kingdom is the famous Lio Shan monastery. Gods constructed three diamond pillars on the monastery's lawn long ago. Gods also placed on one pillar n golden disks of different diameters (in the order of the diameters' decreasing from the bottom to the top). Besides, gods commanded to carry all the disks from the first pillar to the third one according to the following rules:

  * you can carry only one disk in one move;
  * you cannot put a larger disk on a smaller one.

There was no universal opinion concerning what is to happen after the gods' will is done: some people promised world peace and eternal happiness to everyone, whereas others predicted that the kingdom will face communi… (gee, what am I rambling about?) the Armageddon. However, as everybody knew that it was impossible to solve the problem in less than 2n - 1 moves and the lazy Lio Shan monks never even started to solve it, everyone lives peacefully even though the problem was never solved and nobody was afraid of the Armageddon.

However, the monastery wasn't doing so well lately and the wise prior Ku Sean Sun had to cut some disks at the edges and use the gold for the greater good. Wouldn't you think that the prior is entitled to have an air conditioning system? Besides, staying in the monastery all year is sooo dull… One has to have a go at something new now and then, go skiing, for example… Ku Sean Sun realize how big a mistake he had made only after a while: after he cut the edges, the diameters of some disks got the same; that means that some moves that used to be impossible to make, were at last possible (why, gods never prohibited to put a disk on a disk of the same diameter). Thus, the possible Armageddon can come earlier than was initially planned by gods. Much earlier. So much earlier, in fact, that Ku Sean Sun won't even have time to ski all he wants or relax under the air conditioner.

The wise prior could never let that last thing happen and he asked one very old and very wise witch PikiWedia to help him. May be she can determine the least number of moves needed to solve the gods' problem. However, the witch laid out her cards and found no answer for the prior. Then he asked you to help him.

Can you find the shortest solution of the problem, given the number of disks and their diameters? Keep in mind that it is allowed to place disks of the same diameter one on the other one, however, the order in which the disks are positioned on the third pillar in the end should match the initial order of the disks on the first pillar.

Input

The first line contains an integer n — the number of disks (1 ≤ n ≤ 20). The second line contains n integers di — the disks' diameters after Ku Sean Sun cut their edges. The diameters are given from the bottom to the top (1 ≤ di ≤ 20, besides, di ≥ di + 1 for any 1 ≤ i < n).

Output

Print on the first line number m — the smallest number of moves to solve the gods' problem. Print on the next m lines the description of moves: two space-separated positive integers si and ti that determine the number of the pillar from which the disk is moved and the number of pillar where the disk is moved, correspondingly (1 ≤ si, ti ≤ 3, si ≠ ti). 

Examples

Input

3
3 2 1


Output

7
1 3
1 2
3 2
1 3
2 1
2 3
1 3


Input

3
3 1 1


Output

5
1 2
1 2
1 3
2 3
2 3


Input

3
3 3 3


Output

5
1 2
1 2
1 3
2 3
2 3

Note

Pay attention to the third test demonstrating that the order of disks should remain the same in the end, even despite the disks' same radius. If this condition was not necessary to fulfill, the gods' task could have been solved within a smaller number of moves (three — simply moving the three disks from the first pillar on the third one).
#include <bits/stdc++.h>
using std::abs;
using std::bitset;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::sort;
using std::string;
using std::swap;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using ld = long double;
template <typename T>
void _dbg(const char* s, T h) {
  cerr << s << " = " << h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* s, T h, Ts... t) {
  int b = 0;
  while (((b += *s == '(') -= *s == ')') != 0 || *s != ',') cerr << *s++;
  cerr << " = " << h << ",";
  _dbg(s + 1, t...);
}
struct init {
  init() {
    cin.tie(0);
    std::iostream::sync_with_stdio(0);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);
  }
  ~init() {}
} init;
template <typename T, typename U>
void upx(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
void upn(T& x, U y) {
  if (x > y) x = y;
}
const ll N = 22;
ll a[N];
ll b[N];
ll second = 0;
vector<pll> ans;
void solve(ll x, ll y, ll c);
void solverev(ll x, ll y, ll c) {
  ll t = 6 - x - y;
  if (c) {
    solverev(x, t, c - 1);
    for (ll i = 0; i < (b[c]); ++i) ans.emplace_back(x, y);
    solverev(t, y, c - 1);
  } else {
    for (ll i = 0; i < (b[c]); ++i) ans.emplace_back(x, y);
  }
}
void solve(ll x, ll y, ll c) {
  ll t = 6 - x - y;
  if (c) {
    if (b[c] == 1) {
      solverev(x, y, c);
    } else {
      solverev(x, y, c - 1);
      for (ll i = 0; i < (b[c]); ++i) ans.emplace_back(x, t);
      solverev(y, x, c - 1);
      for (ll i = 0; i < (b[c]); ++i) ans.emplace_back(t, y);
      solve(x, y, c - 1);
    }
  } else {
    for (ll i = 0; i < (b[c] - 1); ++i) ans.emplace_back(x, t);
    ans.emplace_back(x, y);
    for (ll i = 0; i < (b[c] - 1); ++i) ans.emplace_back(t, y);
  }
}
int32_t main() {
  ll n;
  cin >> n;
  map<ll, ll> m;
  for (ll i = 0; i < (n); ++i) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (auto p : m) b[second++] = p.second;
  solve(1, 3, second - 1);
  cout << ans.size() << '\n';
  for (pll p : ans) cout << p.first << ' ' << p.second << '\n';
  return 0;
}
