#include <bits/stdc++.h>
using namespace std;
void fastIO();
vector<pair<int, pair<int, int>>> ans;
void qsort(vector<pair<int, int>> &a, int lef, int rig, int k) {
  if (lef >= rig) {
    return;
  }
  int i = lef, j = rig, mid = a[(i + j) >> 1].first;
  while (i <= j) {
    while (a[i].first < mid) {
      ++i;
    }
    while (mid < a[j].first) {
      --j;
    }
    if (i <= j) {
      if (i != j) {
        ans.push_back({k, {i + 1, j + 1}});
        swap(a[i], a[j]);
      }
      ++i;
      --j;
    }
  }
  qsort(a, lef, j, k);
  qsort(a, i, rig, k);
}
int main() {
  fastIO();
  int n;
  cin >> n;
  vector<pair<int, int>> a(n - 1);
  for (auto &i : a) {
    cin >> i.first >> i.second;
    --i.first;
    --i.second;
  }
  vector<pair<int, int>> row(n);
  for (int i = (int)0; i < (int)n; ++i) {
    row[i].second = i;
    row[i].first = 0;
  }
  for (auto i : a) {
    row[i.first].first++;
  }
  qsort(row, 0, n - 1, 1);
  vector<int> cur(n);
  for (int i = (int)0; i < (int)n; ++i) {
    cur[row[i].second] = i;
  }
  vector<pair<int, int>> col(n);
  for (int i = (int)0; i < (int)n; ++i) {
    col[i].second = i;
    col[i].first = 0;
  }
  for (auto i : a) {
    col[i.second].first = min(col[i.second].first, cur[i.first] - n);
  }
  qsort(col, 0, n - 1, 2);
  cout << (int)ans.size() << '\n';
  for (auto i : ans) {
    cout << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
  }
  return 0;
}
void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
