#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int m, o1[100001], o2[100001], t[100001];
void f(int n) {
  int c = -1;
  if (n == 1) return;
  for (int i = 1; i <= n; i++) {
    bool b = 0;
    for (int j = 1; j <= n; j++)
      if (a[j][i]) {
        b = 1;
        break;
      }
    if (!b) {
      c = i;
      break;
    }
  }
  if (n != c) {
    for (int i = 1; i <= n; i++) swap(a[i][n], a[i][c]);
    m++;
    o1[m] = c;
    o2[m] = n;
    t[m] = 2;
  }
  int r = -1;
  for (int j = n; j >= 1; j--) {
    bool b = 0;
    for (int i = n - 1; i >= 1; i--)
      if (a[j][i]) {
        b = 1;
        break;
      }
    if (b) {
      r = j;
      break;
    }
  }
  if (r == -1) return;
  for (int i = 1; i <= n; i++) swap(a[n][i], a[r][i]);
  if (n != r) {
    m++;
    o1[m] = r;
    o2[m] = n;
    t[m] = 1;
  }
  f(n - 1);
}
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x][y] = 1;
  }
  f(n);
  cout << m << endl;
  for (int i = 1; i <= m; i++)
    cout << t[i] << " " << o1[i] << " " << o2[i] << endl;
}
