#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
struct Matrix {
  Matrix(int y, int x);
  void swapRows(int x, int y);
  void swapColumns(int x, int y);
  int pos(int f, int c);
  void assignVal(int x, int y, int val);
  vector<int> _rows;
  vector<int> _columns;
  vector<vector<int> > _matrix;
  vector<int> _rowCount;
  vector<int> _colCount;
  int _maxY;
  int _maxX;
};
void Matrix::assignVal(int x, int y, int val) {
  int prev = pos(x, y);
  _matrix[_rows[x]][_columns[y]] = val;
  if (val != 0 && prev == 0) {
    _rowCount[x]++;
    _colCount[y]++;
  }
  if (val == 0 && prev != 0) {
    _rowCount[x]--;
    _colCount[y]--;
  }
}
int Matrix::pos(int f, int c) { return _matrix[_rows[f]][_columns[c]]; }
void Matrix::swapColumns(int x, int y) {
  swap(_columns[x], _columns[y]);
  swap(_colCount[x], _colCount[y]);
}
void Matrix::swapRows(int x, int y) {
  swap(_rows[x], _rows[y]);
  swap(_rowCount[x], _rowCount[y]);
}
Matrix::Matrix(int y, int x) {
  _maxY = y;
  _maxX = x;
  _rows.clear();
  _columns.clear();
  _matrix.clear();
  _colCount.clear();
  _rowCount.clear();
  for (int i = 0; i < _maxY; i++) {
    _rows.push_back(i);
    _rowCount.push_back(0);
  }
  for (int i = 0; i < _maxX; i++) {
    _columns.push_back(i);
    _colCount.push_back(0);
  }
  for (int i = 0; i < _maxY; i++) {
    vector<int> theRow(_maxX);
    for (int j = 0; j < _maxX; j++) theRow[j] = 0;
    _matrix.push_back(theRow);
  }
}
void add(vector<int>& res, int i, int a, int b) {
  if (a == b) return;
  res.push_back(i);
  res.push_back(a + 1);
  res.push_back(b + 1);
}
void show(vector<int>& res) {
  cout << res.size() / 3 << endl;
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << " ";
    if (i % 3 == 2) cout << endl;
  }
  cout << endl;
}
int main() {
  int n;
  while (cin >> n) {
    vector<int> res;
    Matrix m(n, n);
    vector<int> outs;
    for (int i = 0; i < n - 1; i++) {
      int x, y;
      cin >> x >> y;
      m.assignVal(x - 1, y - 1, 1);
    }
    int lo = 0, hi = n - 1;
    while (lo < hi) {
      int maxRow = lo;
      int maxCol = lo;
      for (int i = lo; i < hi + 1; i++) {
        if (m._rowCount[i] > m._rowCount[maxRow]) maxRow = i;
      }
      for (int i = lo; i < hi + 1; i++) {
        if (m._colCount[i] - m.pos(maxRow, i) >
            m._colCount[maxCol] - m.pos(maxRow, maxCol))
          maxCol = i;
      }
      m.swapRows(hi, maxRow);
      add(res, 1, hi, maxRow);
      m.swapColumns(lo, maxCol);
      add(res, 2, lo, maxCol);
      if (m._rowCount[lo] > 0) {
        maxRow = lo;
        while (m._rowCount[maxRow] > 0) maxRow++;
        m.swapRows(lo, maxRow);
        add(res, 1, lo, maxRow);
      }
      if (m._colCount[hi] > 0) {
        maxCol = hi;
        while (m._colCount[maxCol] > 0) maxCol--;
        m.swapColumns(hi, maxCol);
        add(res, 2, hi, maxCol);
      }
      for (int i = lo; i < hi + 1; i++) {
        m.assignVal(lo, i, 0);
        m.assignVal(hi, i, 0);
        m.assignVal(i, lo, 0);
        m.assignVal(i, hi, 0);
      }
      lo++;
      hi--;
    }
    show(res);
  }
  return 0;
}
