#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > Log;
vector<int> Sizes;
vector<int> Pil[3];
int N;
int Data[20];
void move(int a, int b) {
  int u = Pil[a].back();
  Pil[a].pop_back();
  Pil[b].push_back(u);
  Log.push_back(pair<int, int>(a, b));
}
void allMove(int k, int from, int to) {
  while (!Pil[from].empty() && Data[Pil[from].back()] == k) move(from, to);
}
void dododo(int k, int from, int to) {
  if (Pil[from].empty() || Data[Pil[from].back()] >= k) return;
  int big = -1, n = Pil[from].size();
  for (int i = n - 1; i >= 0; --i) {
    if (Data[Pil[from][i]] >= k) break;
    big = max(big, Data[Pil[from][i]]);
  }
  dododo(big, from, 3 - from - to);
  allMove(big, from, to);
  dododo(big, 3 - from - to, to);
}
void findFromPil(int val, int &id, int &rev, int &cnt) {
  vector<int> cnd;
  for (int q = 0; q < 3; ++q)
    for (int w = 0; w < Pil[q].size(); ++w)
      if (Data[Pil[q][w]] == val) {
        id = q;
        cnd.push_back(q * 100 + Pil[q][w]);
      }
  rev = (cnd.size() == 1 || cnd[0] > cnd[1]);
  cnt = cnd.size();
}
int main() {
  scanf("%d", &N);
  for (int q = 0; q < N; ++q) scanf("%d", Data + q);
  Sizes = vector<int>(Data, Data + N);
  Sizes.erase(unique(Sizes.begin(), Sizes.end()), Sizes.end());
  for (int q = 0; q < N; ++q) Pil[0].push_back(q);
  for (int q = 0; q < Sizes.size(); ++q) {
    int stand = Sizes[q];
    int where, reversed, cnt;
    findFromPil(stand, where, reversed, cnt);
    if (where == 2) {
      while (1)
        ;
      return 0;
    }
    if (reversed) {
      dododo(stand, where, 1 - where);
      allMove(stand, where, 2);
    } else if (Data[Pil[where].back()] != stand) {
      dododo(stand, where, 2);
      allMove(stand, where, 1 - where);
      dododo(stand, 2, where);
      allMove(stand, 1 - where, 2);
    } else {
      for (int w = 0; w + 1 < cnt; ++w) move(where, 1 - where);
      move(where, 2);
      for (int w = 0; w + 1 < cnt; ++w) move(1 - where, 2);
    }
  }
  printf("%u\n", Log.size());
  for (int q = 0; q < Log.size(); ++q)
    printf("%d %d\n", Log[q].first + 1, Log[q].second + 1);
  return 0;
}
