#include <bits/stdc++.h>
using namespace std;
int rsz[1005], csz[1005], arr[1005][1005], n;
vector<pair<int, int> > out;
vector<int> t;
void solve(int s) {
  if (s == n - 1) return;
  for (int i = s + 1; i < n; i++) {
    if (!rsz[i]) {
      t.push_back(1);
      out.push_back(pair<int, int>(s, i));
      for (int j = 0; j < n; j++) swap(arr[s][j], arr[i][j]);
      swap(rsz[s], rsz[i]);
      break;
    }
  }
  for (int j = s + 1; j < n; j++) {
    if (csz[j]) {
      t.push_back(2);
      out.push_back(pair<int, int>(s, j));
      for (int i = 0; i < n; i++) swap(arr[i][s], arr[i][j]);
      swap(csz[s], csz[j]);
      break;
    }
  }
  for (int i = s + 1; i < n; i++)
    if (arr[i][s]) --rsz[i];
  solve(s + 1);
}
int main() {
  scanf("%d", &n);
  for (int C = 0; C < n - 1; ++C) {
    int i, j;
    scanf("%d", &i), scanf("%d", &j);
    i--, j--;
    arr[i][j] = 1;
    ++rsz[i];
    ++csz[j];
  }
  solve(0);
  cout << out.size() << endl;
  for (int i = 0; i < out.size(); ++i)
    printf("%d %d %d\n", t[i], out[i].first + 1, out[i].second + 1);
}
