#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e14 + 9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<vector<long long>> mat(n, vector<long long>(n, 0));
  for (long long i = 0; i < (n - 1); ++i) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    mat[a][b] = 1;
  }
  vector<int> rows(n, 0), cl(n, 0);
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (n); ++j) {
      rows[i] += mat[i][j];
    }
  }
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (n); ++j) {
      cl[i] += mat[j][i];
    }
  }
  long long ult = n;
  long long n2 = n - 1;
  vector<pair<long long, pair<long long, long long>>> ans;
  while (n2--) {
    long long ind = -1;
    for (long long i = 0; i < ((long long)(rows).size()); ++i) {
      if (rows[i] > 0) {
        ind = i;
      }
    }
    if (ind == -1) {
      break;
    }
    ans.push_back({1, {ind + 1, ult}});
    rows[ind] = -1;
    swap(rows[ind], rows[ult - 1]);
    swap(mat[ind], mat[ult - 1]);
    for (long long i = 0; i < ((long long)(cl).size()); ++i) {
      if (cl[i] == 0) ind = i;
    }
    ans.push_back({2, {ind + 1, ult}});
    cl[ind] = -1;
    swap(cl[ind], cl[ult - 1]);
    for (long long i = 0; i < (n); ++i) {
      swap(mat[i][ind], mat[i][ult - 1]);
    }
    for (long long i = 0; i < (n); ++i) {
      cl[i] -= mat[ult - 1][i];
    }
    ult--;
  }
  long long ansf = (long long)(ans).size();
  for (long long i = 0; i < ((long long)(ans).size()); ++i) {
    if (ans[i].second.first == ans[i].second.second) ansf--;
  }
  cout << ansf << "\n";
  for (long long i = 0; i < ((long long)(ans).size()); ++i) {
    if (ans[i].second.first != ans[i].second.second)
      cout << ans[i].first << " " << ans[i].second.first << " "
           << ans[i].second.second << "\n";
  }
  return 0;
}
