#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> row(n + 1);
  for (int i = 0; i <= n; ++i) row[i] = i;
  vector<int> rinv(row), col(row), cinv(row);
  vector<pair<int, int> > rans, cans;
  rans.reserve(n);
  cans.reserve(n);
  for (int i = 1, r, c; i < n; ++i) {
    cin >> r >> c;
    if (col[c] < row[r] && row[r] <= i + 1) continue;
    if (row[r] != i + 1) {
      rans.push_back(make_pair(row[r], i + 1));
      rinv[row[r]] = rinv[i + 1];
      swap(row[r], row[rinv[i + 1]]);
      rinv[i + 1] = r;
    }
    if (col[c] > i) {
      cans.push_back(make_pair(col[c], i));
      cinv[col[c]] = cinv[i];
      swap(col[c], col[cinv[i]]);
      cinv[i] = c;
    }
  }
  cout << rans.size() + cans.size() << '\n';
  for (int i = 0; i < rans.size(); ++i)
    cout << 1 << ' ' << rans[i].first << ' ' << rans[i].second << '\n';
  for (int i = 0; i < cans.size(); ++i)
    cout << 2 << ' ' << cans[i].first << ' ' << cans[i].second << '\n';
  cin.get();
  cin.get();
  return 0;
}
