#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
long long n, m, k, ar[1000005], br[1000005];
string s, s1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    cin >> n;
    vector<int> row(n + 1), col(n + 1), row_left(n + 1, n + 1),
        col_top(n + 1, n + 1);
    vector<vector<int>> row_me_col(n + 1);
    for (int i = 1; i < n; i++) {
      int r, c;
      cin >> r >> c;
      row[r]++;
      row_left[r] = min(row_left[r], c);
      row_me_col[r].push_back(c);
      col[c]++;
    }
    vector<pair<int, int>> ansr, ansc;
    for (int i = 1; i < n; i++) {
      int mini = i;
      for (int j = i + 1; j <= n; j++) {
        if (row[mini] > row[j]) {
          mini = j;
        } else if (row[mini] == row[j] && row_left[mini] > row[j]) {
          mini = j;
        }
      }
      if (i == mini) continue;
      ansr.push_back(make_pair(i, mini));
      swap(row[i], row[mini]);
      swap(row_me_col[i], row_me_col[mini]);
      swap(row_left[i], row_left[mini]);
    }
    int cnt = 1;
    for (auto i : row_me_col) {
      for (auto j : i) col_top[j] = min(col_top[j], cnt);
      cnt++;
    }
    for (int i = 1; i < n; i++) {
      int mini = i;
      for (int j = i + 1; j <= n; j++) {
        if (col[mini] < col[j]) {
          mini = j;
        } else if (col[j] == col[mini] && col_top[mini] > col_top[j]) {
          mini = j;
        }
      }
      if (i == mini) continue;
      ansc.push_back(make_pair(i, mini));
      swap(col[i], col[mini]);
      swap(col_top[i], col_top[mini]);
    }
    cout << ansr.size() + ansc.size() << endl;
    for (auto i : ansr) cout << "1 " << i.first << " " << i.second << endl;
    for (auto i : ansc) cout << "2 " << i.first << " " << i.second << endl;
  }
  return 0;
}
