#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > d, ans;
int f[21][2], kind[21];
void dfs(int from, int to, int swap, int k, int depth) {
  if (depth == (int)d.size()) return;
  if (k == 1 || d[depth].second == 1) {
    dfs(from, swap, to, 1, depth + 1);
    for (int i = 0; i < d[depth].second; ++i)
      ans.push_back(make_pair(from, to));
    dfs(swap, to, from, 1, depth + 1);
    return;
  }
  if (kind[depth] == 0) {
    dfs(from, to, swap, 1, depth + 1);
    for (int i = 1; i < d[depth].second; ++i)
      ans.push_back(make_pair(from, swap));
    dfs(to, swap, from, 1, depth + 1);
    ans.push_back(make_pair(from, to));
    dfs(swap, from, to, 1, depth + 1);
    for (int i = 1; i < d[depth].second; ++i)
      ans.push_back(make_pair(swap, to));
    dfs(from, to, swap, 1, depth + 1);
  } else {
    dfs(from, to, swap, 1, depth + 1);
    for (int i = 0; i < d[depth].second; ++i)
      ans.push_back(make_pair(from, swap));
    dfs(to, from, swap, 1, depth + 1);
    for (int i = 0; i < d[depth].second; ++i)
      ans.push_back(make_pair(swap, to));
    dfs(from, to, swap, 0, depth + 1);
  }
}
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (d.size() == 0u || d.back().first != x) {
      d.push_back(make_pair(x, 1));
    } else {
      ++d.back().second;
    }
  }
  f[d.size()][0] = f[d.size()][1] = 0;
  for (int i = (int)d.size() - 1; i >= 0; --i) {
    f[i][1] = f[i + 1][1] * 2 + d[i].second;
    if (d[i].second == 1) {
      f[i][0] = 2 * f[i + 1][1] + 1;
      kind[i] = 2;
    } else {
      f[i][0] = 4 * f[i + 1][1] + 2 * d[i].second - 1;
      kind[i] = 0;
      int val = 2 * f[i + 1][1] + f[i + 1][0] + 2 * d[i].second;
      if (val < f[i][0]) {
        f[i][0] = val;
        kind[i] = 1;
      }
    }
  }
  dfs(1, 3, 2, 0, 0);
  printf("%u\n", ans.size());
  for (size_t i = 0; i < ans.size(); ++i)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}
