#include <bits/stdc++.h>
using namespace std;
int n, p, cnt;
int a[3005], b[3005], row[3005], col[3005], r[3005], R[3005], c[3005], C[3005],
    Rt[3005];
int rew[3005], rex[3005], rey[3005];
bool cmpC(int x, int y) { return col[x] > col[y]; }
bool cmpR(int x, int y) { return Rt[x] < Rt[y]; }
void add(int w, int x, int y) {
  rew[cnt] = w, rex[cnt] = x, rey[cnt] = y, ++cnt;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n - 1); i++) {
    scanf("%d%d", &a[i], &b[i]);
    --a[i], --b[i];
    row[a[i]]++, col[b[i]]++;
  }
  for (int i = (0); i < (n); i++) R[i] = C[i] = r[i] = c[i] = i, Rt[i] = -1;
  sort(C, C + n, cmpC);
  for (int i = (0); i < (n); i++) {
    if (c[i] != C[i]) {
      for (int j = (0); j < (n); j++)
        if (c[j] == C[i]) p = j;
      swap(c[i], c[p]);
      for (int j = (0); j < (n - 1); j++)
        if (b[j] == i)
          b[j] = p;
        else if (b[j] == p)
          b[j] = i;
      add(2, i, p);
    }
  }
  for (int i = (0); i < (n - 1); i++) Rt[a[i]] = max(Rt[a[i]], b[i]);
  sort(R, R + n, cmpR);
  for (int i = (n)-1; i >= (0); i--) {
    if (r[i] != R[i]) {
      for (int j = (0); j < (n); j++)
        if (r[j] == R[i]) p = j;
      swap(r[i], r[p]);
      add(1, i, p);
    }
  }
  printf("%d\n", cnt);
  for (int i = (0); i < (cnt); i++)
    printf("%d %d %d\n", rew[i], rex[i] + 1, rey[i] + 1);
  return 0;
}
