#include <bits/stdc++.h>
using namespace std;
int plane[1010][1010] = {0};
int x[1010] = {0}, y[1010] = {0};
int tmp[1010];
struct f {
  int a, b, c;
};
queue<f> q;
void func(int d) {
  if (d == 1) {
    return;
  }
  for (int i = d; i > 0; i--) {
    if (y[i] == 0) {
      if (i != d) {
        memcpy(tmp, plane[i], sizeof(plane[i]));
        memcpy(plane[i], plane[d], sizeof(plane[d]));
        memcpy(plane[d], tmp, sizeof(tmp));
        q.push((f){2, i, d});
        swap(y[i], y[d]);
      }
      break;
    }
  }
  if (x[d] == 0) {
    for (int i = 1; i < d; i++) {
      if (x[i]) {
        for (int j = 1; j <= d; j++) {
          swap(plane[j][i], plane[j][d]);
        }
        q.push((f){1, i, d});
        swap(x[i], x[d]);
        break;
      }
    }
  }
  for (int i = 1; i <= d; i++) {
    if (plane[i][d]) {
      y[i]--;
    }
  }
  func(d - 1);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n - 1); i++) {
    int tx, ty;
    scanf("%d%d", &tx, &ty);
    plane[ty][tx] = 1;
    x[tx]++;
    y[ty]++;
  }
  func(n);
  printf("%d\n", (int)q.size());
  while (!q.empty()) {
    printf("%d %d %d\n", q.front().a, q.front().b, q.front().c);
    q.pop();
  }
  return 0;
}
