#include <bits/stdc++.h>
using namespace std;
int is[1010][1010];
int num[1010];
int n;
void sphang(int i, int j) {
  swap(is[i], is[j]);
  swap(num[i], num[j]);
}
void splie(int i, int j) {
  for (int k = 1; k <= n; k++) swap(is[k][i], is[k][j]);
}
vector<int> ans1, ans2, ans3;
int usd[1010];
int sta[1100], top;
int main() {
  cin >> n;
  int r, s;
  int i, j;
  for (i = 1; i <= n - 1; i++) {
    cin >> r >> s;
    is[r][s] = 1;
    num[r]++;
  }
  for (i = 1; i <= n; i++) {
    int M = 210000;
    for (j = i; j <= n; j++)
      if (M > num[j]) M = num[j], s = j;
    sphang(i, s);
    if (i - s) ans1.push_back(1), ans2.push_back(i), ans3.push_back(s);
    top = 0;
    for (j = 1; j < i; j++)
      if (!usd[j] && !is[i][j])
        sta[++top] = j;
      else if (!usd[j])
        usd[j] = 1;
    for (j = i; j <= n; j++)
      if (is[i][j]) {
        int t = sta[top--];
        ans1.push_back(2);
        ans2.push_back(t);
        ans3.push_back(j);
        splie(t, j);
        usd[t] = 1;
      }
  }
  printf("%d\n", ans1.size());
  for (i = 0; i < ans1.size(); i++)
    printf("%d %d %d\n", ans1[i], ans2[i], ans3[i]);
}
