Problem: You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to n from left to right. Some cells (n - 1 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can apply the following operations to the matrix:

  1. Swap i-th and j-th rows of the matrix; 
  2. Swap i-th and j-th columns of the matrix. 



You are asked to transform the matrix into a special form using these operations. In that special form all the ones must be in the cells that lie below the main diagonal. Cell of the matrix, which is located on the intersection of the i-th row and of the j-th column, lies below the main diagonal if i > j.

Input

The first line contains an integer n (2 ≤ n ≤ 1000) — the number of rows and columns. Then follow n - 1 lines that contain one's positions, one per line. Each position is described by two integers xk, yk (1 ≤ xk, yk ≤ n), separated by a space. A pair (xk, yk) means that the cell, which is located on the intersection of the xk-th row and of the yk-th column, contains one.

It is guaranteed that all positions are distinct.

Output

Print the description of your actions. These actions should transform the matrix to the described special form.

In the first line you should print a non-negative integer m (m ≤ 105) — the number of actions. In each of the next m lines print three space-separated integers t, i, j (1 ≤ t ≤ 2, 1 ≤ i, j ≤ n, i ≠ j), where t = 1 if you want to swap rows, t = 2 if you want to swap columns, and i and j denote the numbers of rows or columns respectively.

Please note, that you do not need to minimize the number of operations, but their number should not exceed 105. If there are several solutions, you may print any of them.

Examples

Input

2
1 2


Output

2
2 1 2
1 1 2


Input

3
3 1
1 3


Output

3
2 2 3
1 1 3
1 1 2


Input

3
2 1
3 2


Output

0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    long long int t = bigmod(p, e / 2, M);
    return (T)((t * t) % M);
  }
  return (T)((long long int)bigmod(p, e - 1, M) * (long long int)p) % M;
}
template <class T>
inline T bigexp(T p, T e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    long long int t = bigexp(p, e / 2);
    return (T)((t * t));
  }
  return (T)((long long int)bigexp(p, e - 1) * (long long int)p);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct T {
  int id, val;
  bool operator<(const T& p) const { return val > p.val; }
} ed[1005];
int n, m, a[1005][1005], xx[1005][1005], cc, dd[1005][2], np[1005],
    ne[1005][1005], b[1005], k, x, y, c, d[1005], emprow, empcol;
pair<int, pair<int, int> > p[100005];
int main() {
  scanf("%d", &n);
  for (__typeof(n - 1) i = (1); i <= (n - 1); i++) {
    scanf("%d %d", &x, &y);
    a[x][y] = 1;
    b[y]++;
    d[x]++;
    xx[x][y] = 1;
  }
  empcol = 0;
  for (__typeof(n) i = (1); i <= (n); i++) {
    if (b[i] > 0) {
      ed[++c].id = i;
      ed[c].val = b[i];
    } else if (b[i] == 0 && empcol == 0)
      empcol = i;
  }
  for (__typeof(n) i = (1); i <= (n); i++) {
    if (d[i] == 0) emprow = i;
  }
  sort(ed + 1, ed + c + 1);
  for (__typeof(n) i = (1); i <= (n); i++) np[i] = i;
  if (empcol != 1) {
    p[++m].first = 2;
    p[m].second.first = 1;
    p[m].second.second = empcol;
    for (__typeof(n) j = (1); j <= (n); j++) {
      a[j][empcol] = a[j][1];
      a[j][1] = 0;
    }
    for (__typeof(c) j = (1); j <= (c); j++)
      if (ed[j].id == 1) {
        ed[j].id = empcol;
      }
    empcol = 1;
  }
  int tmp;
  for (__typeof(c) i = (1); i <= (c); i++) {
    if (empcol == i && ed[i].id != i) {
      p[++m].first = 2;
      p[m].second.first = i;
      p[m].second.second = ed[i].id;
      for (__typeof(n) j = (1); j <= (n); j++) {
        a[j][i] = a[j][ed[i].id];
        a[j][ed[i].id] = 0;
      }
      tmp = ed[i].id;
      ed[i].id = empcol;
      empcol = tmp;
    } else if (ed[i].id != i) {
      p[++m].first = 2;
      p[m].second.first = empcol;
      p[m].second.second = i;
      for (__typeof(n) j = (1); j <= (n); j++) {
        a[j][empcol] = a[j][i];
        a[j][i] = 0;
      }
      for (__typeof(c) j = (1); j <= (c); j++)
        if (ed[j].id == i) {
          ed[j].id = empcol;
        }
      empcol = i;
      p[++m].first = 2;
      p[m].second.first = empcol;
      p[m].second.second = ed[i].id;
      for (__typeof(n) j = (1); j <= (n); j++) {
        a[j][empcol] = a[j][ed[i].id];
        a[j][ed[i].id] = 0;
      }
      tmp = ed[i].id;
      ed[i].id = empcol;
      empcol = tmp;
    } else {
      for (__typeof(n) j = (1); j <= (n); j++) {
        a[j][i] = a[j][ed[i].id];
      }
      ed[i].id = i;
    }
  }
  for (__typeof(1) i = (n); i >= (1); i--)
    for (__typeof(n) j = (1); j <= (n); j++)
      if (a[j][i] == 1) {
        dd[++cc][0] = j;
        dd[cc][1] = i;
      }
  int target = n;
  if (emprow != n) {
    p[++m].first = 1;
    p[m].second.first = n;
    p[m].second.second = emprow;
    for (__typeof(cc) j = (1); j <= (cc); j++)
      if (dd[j][0] == n) dd[j][0] = emprow;
    emprow = n;
  }
  for (int i = 1; i <= cc && target > 1; i++) {
    x = dd[i][0];
    if (x >= target) {
      for (__typeof(cc) j = (1); j <= (cc); j++)
        if (dd[j][0] == x) dd[j][0] = target;
      if (x == target) {
        for (__typeof(cc) j = (1); j <= (cc); j++)
          if (dd[j][0] == x) dd[j][0] = target;
        target--;
      }
      continue;
    } else {
      if (emprow == target) {
        p[++m].first = 1;
        p[m].second.first = target;
        p[m].second.second = x;
        for (__typeof(cc) j = (1); j <= (cc); j++)
          if (dd[j][0] == x) dd[j][0] = target;
        emprow = x;
        target--;
      } else {
        p[++m].first = 1;
        p[m].second.first = target;
        p[m].second.second = emprow;
        for (__typeof(cc) j = (1); j <= (cc); j++)
          if (dd[j][0] == target) dd[j][0] = emprow;
        emprow = target;
        p[++m].first = 1;
        p[m].second.first = target;
        p[m].second.second = x;
        for (__typeof(cc) j = (1); j <= (cc); j++)
          if (dd[j][0] == x) dd[j][0] = target;
        emprow = x;
        target--;
      }
    }
  }
  printf("%d\n", m);
  for (__typeof(m) i = (1); i <= (m); i++) {
    printf("%d %d %d\n", p[i].first, p[i].second.first, p[i].second.second);
  }
  return 0;
}