#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > V;
const int maxn = 1010;
int n, N;
int a[maxn][maxn], r[maxn], c[maxn];
void sr(int x, int y) {
  if (x == y) return;
  V.push_back(make_pair(1, pair<int, int>(x, y)));
  for (int i = 1; i <= N; ++i) swap(a[x][i], a[y][i]);
  swap(r[x], r[y]);
}
void sc(int x, int y) {
  if (x == y) return;
  V.push_back(make_pair(2, pair<int, int>(x, y)));
  for (int i = 1; i <= N; ++i) swap(a[i][x], a[i][y]);
  swap(c[x], c[y]);
}
int main() {
  int x, y, i, j;
  scanf("%d", &n), N = n;
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    a[x][y] = 1, ++r[x], ++c[y];
  }
  while (n > 1) {
    for (i = 1; i <= n; ++i) {
      for (j = i; j <= n; ++j)
        if (a[i][j]) break;
      if (a[i][j]) break;
    }
    if (!a[i][j]) break;
    sr(i, n), sc(j, 1);
    for (i = 1; i <= n; ++i)
      if (!c[i]) break;
    sc(i, n);
    for (i = 1; i <= n; ++i) c[i] -= a[n][i], r[i] -= a[i][n];
    --n;
  }
  printf("%d\n", V.size());
  for (typeof(V.end()) i = V.begin(); i != V.end(); ++i)
    printf("%d %d %d\n", i->first, (i->second).first, (i->second).second);
  return 0;
}
