#include <bits/stdc++.h>
using namespace std;
int R[1009], C[1009];
int A[100009], B[100009], CC[100009];
int X[1009], Y[1009];
int RF[1009], CF[1009], CFF[1009], RFlag[1009];
int main() {
  int n, N;
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) {
      R[i] = 0;
      C[i] = 0;
      RF[i] = i;
      CF[i] = i;
      CFF[i] = i;
      RFlag[i] = 0;
    }
    for (int i = 1; i <= n - 1; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      X[i] = x;
      Y[i] = y;
      R[x]++;
      C[y]++;
    }
    N = 0;
    for (int i = n; i >= 1; i--) {
      int maxi = i;
      for (int j = 1; j <= n; j++)
        if (RFlag[j] == 0) {
          if (R[RF[j]] > R[RF[maxi]]) maxi = j;
        }
      if (maxi != i) {
        A[N] = 1;
        B[N] = i;
        CC[N] = maxi;
        N++;
        int z = RF[maxi];
        RF[maxi] = RF[i];
        RF[i] = z;
      }
      RFlag[i] = 1;
    }
    int currentColumn = 1;
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j <= n - 1; j++)
        if (X[j] == RF[i]) {
          if (currentColumn == CF[Y[j]])
            currentColumn++;
          else if (currentColumn < CF[Y[j]]) {
            A[N] = 2;
            B[N] = currentColumn;
            CC[N] = CF[Y[j]];
            N++;
            int tt = CFF[currentColumn];
            int z = CF[tt];
            CF[tt] = CF[Y[j]];
            CF[Y[j]] = z;
            CFF[CF[Y[j]]] = Y[j];
            CFF[CF[tt]] = tt;
            currentColumn++;
          }
        }
    }
    printf("%d\n", N);
    for (int i = 0; i < N; i++) printf("%d %d %d\n", A[i], B[i], CC[i]);
  }
  return 0;
}
