#include <bits/stdc++.h>
using namespace std;
int A[32];
int R[32][32][2];
int F(int from, int to, int rev) {
  if (from == to) return 0;
  int& res = R[from][to][rev];
  if (res != -1) return res;
  int mid = from;
  while (mid < to && A[mid] == A[from]) ++mid;
  int cnt = mid - from;
  if (mid == to) return rev == 0 ? cnt + cnt - 1 : cnt;
  if (rev == 1) return res = cnt + 2 * F(mid, to, 1);
  res = min(cnt + cnt + 2 * F(mid, to, 1) + F(mid, to, 0),
            1 + 2 * F(from + 1, to, 1));
  return res;
}
void F(int from, int to, int a, int b, int c, int rev,
       vector<pair<int, int> >& r) {
  int mid = from;
  while (mid < to && A[mid] == A[from]) ++mid;
  int i;
  int cnt = mid - from;
  if (mid == to) {
    if (rev == 0) {
      for (i = (1); i < (cnt); ++i) r.push_back(pair<int, int>(a, b));
      r.push_back(pair<int, int>(a, c));
      for (i = (1); i < (cnt); ++i) r.push_back(pair<int, int>(b, c));
    } else {
      for (i = (0); i < (cnt); ++i) r.push_back(pair<int, int>(a, c));
    }
    return;
  }
  if (rev == 0) {
    if (cnt + cnt + 2 * F(mid, to, 1) + F(mid, to, 0) <
        1 + 2 * F(from + 1, to, 1)) {
      F(mid, to, a, b, c, 1, r);
      for (i = (0); i < (cnt); ++i) r.push_back(pair<int, int>(a, b));
      F(mid, to, c, b, a, 1, r);
      for (i = (0); i < (cnt); ++i) r.push_back(pair<int, int>(b, c));
      F(mid, to, a, b, c, 0, r);
    } else {
      F(from + 1, to, a, c, b, 1, r);
      r.push_back(pair<int, int>(a, c));
      F(from + 1, to, b, a, c, 1, r);
    }
  } else {
    F(mid, to, a, c, b, 1, r);
    for (i = (0); i < (cnt); ++i) r.push_back(pair<int, int>(a, c));
    F(mid, to, b, a, c, 1, r);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = (0); i < (n); ++i) scanf("%d", &A[i]);
  vector<pair<int, int> > r;
  memset(R, -1, sizeof(R));
  F(0, n, 0, 1, 2, 0, r);
  printf("%d\n", int((r).size()));
  for (i = (0); i < (int((r).size())); ++i)
    printf("%d %d\n", r[i].first + 1, r[i].second + 1);
  return 0;
};
