#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> tab;
vector<int> sx, sy;
vector<pair<int, pair<int, int>>> steps;
void swapcol(int i, int j, int sz) {
  swap(sy[i], sy[j]);
  steps.push_back({2, {i + 1, j + 1}});
  for (int k = 0; k < sz; k++) {
    if (tab[k][i] != tab[k][j]) swap(tab[k][i], tab[k][j]);
  }
}
void swaprow(int i, int j, int sz) {
  swap(sx[i], sx[j]);
  steps.push_back({1, {i + 1, j + 1}});
  for (int k = 0; k < sz; k++) {
    if (tab[i][k] != tab[j][k]) swap(tab[i][k], tab[j][k]);
  }
}
void solve(int sz) {
  bool ok = true;
  for (int i = 0; i < sz; i++) {
    if (sx[i] != 0 || sy[i] != 0) ok = false;
  }
  if (ok) return;
  for (int i = 0; i < sz - 1; i++) {
    if (sy[i] == 0) {
      swapcol(i, sz - 1, sz);
      break;
    }
  }
  for (int i = 0; i < sz - 1; i++) {
    if (sx[i] > 0) {
      swaprow(i, sz - 1, sz);
      break;
    }
  }
  for (int i = 0; i < sz; i++) sy[i] -= tab[sz - 1][i];
  solve(sz - 1);
}
int main() {
  int n, count = 0;
  cin >> n;
  tab = vector<vector<int>>(n, vector<int>(n, 0));
  sx = vector<int>(n, 0);
  sy = vector<int>(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    sx[a - 1]++;
    sy[b - 1]++;
    tab[a - 1][b - 1] = 1;
  }
  solve(n);
  cout << steps.size() << "\n";
  for (int i = 0; i < steps.size(); i++) {
    cout << steps[i].first << " " << steps[i].second.first << " "
         << steps[i].second.second << "\n";
  }
  return 0;
}
