#include <bits/stdc++.h>
using namespace std;
struct data {
  int loai, u, v;
  data(int _loai = 0, int _u = 0, int _v = 0) {
    loai = _loai;
    u = _u;
    v = _v;
  }
} a[1010 * 1010];
int n, sobuoc = 0;
bool dd[1010][1010];
int cot[1010], hang[1010];
void nhap() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d", &u), scanf("%d", &v);
    cot[v]++;
    hang[u]++;
    dd[u][v] = 1;
  }
}
void chuanbi() {}
int Timcot(int u) {
  for (int i = u; i >= 1; i--)
    if (!cot[i]) return i;
}
int Timhang(int u) {
  for (int i = u; i >= 1; i--)
    if (hang[i]) return i;
}
void Refresh(int u) {
  for (int i = 1; i <= u - 1; i++)
    if (dd[u][i]) cot[i]--;
}
void xuli() {
  for (int i = n; i >= 2; i--) {
    int j = Timcot(i);
    if (j != i) {
      a[++sobuoc] = data(2, i, j);
      swap(cot[i], cot[j]);
      for (int k = 1; k <= i; k++) swap(dd[k][i], dd[k][j]);
    }
    j = Timhang(i);
    if (j != i) {
      a[++sobuoc] = data(1, i, j);
      swap(hang[i], hang[j]);
      for (int k = 1; k <= i - 1; k++) swap(dd[i][k], dd[j][k]);
    }
    Refresh(i);
  }
}
void inkq() {
  printf("%d\n", sobuoc);
  for (int i = 1; i <= sobuoc; i++)
    printf("%d %d %d \n", a[i].loai, a[i].u, a[i].v);
}
int main() {
  nhap();
  chuanbi();
  xuli();
  inkq();
  return 0;
}
