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;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long int bst(long long int a[], long long int item, long long int index,
                  long long int n) {
  long long int b = index, e = n, mid;
  mid = (b + e) / 2;
  while (a[mid] != item && b <= e) {
    if (a[mid] < item)
      b = mid + 1;
    else
      e = mid - 1;
    mid = (b + e) / 2;
  }
  return mid;
}
long long int max3(long long int x, long long int y, long long int z) {
  return max(max(x, y), z);
}
long long int min3(long long int x, long long int y, long long int z) {
  return min(min(x, y), z);
}
string cir_shift(string s) {
  string s1;
  long long int len;
  len = s.size();
  s1 = s.substr(1, len - 1);
  s1.push_back(s[0]);
  return s1;
}
template <typename Type>
void swap1(Type &a, Type &b) {
  Type temp;
  temp = a;
  a = b;
  b = temp;
}
long long int a[1001][1001];
void scolumn(long long int x, long long int y, long long int n) {
  long long int i;
  for (i = 1; i <= n; i++) {
    swap1(a[i][x], a[i][y]);
  }
}
void srow(long long int x, long long int y, long long int n) {
  long long int i;
  for (i = 1; i <= n; i++) {
    swap1(a[x][i], a[y][i]);
  }
}
void print(long long int n) {
  long long int i, j;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
bool comp(pair<long long int, long long int> x,
          pair<long long int, long long int> y) {
  return x.second < y.second;
}
bool comp1(pair<long long int, long long int> x,
           pair<long long int, long long int> y) {
  return x.first < y.first;
}
long long int c[1001], d[1001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  vector<pair<long long int, pair<long long int, long long int> > > v;
  long long int n, x, y, cnt = 0, i, j, k, ind, num;
  cin >> n;
  vector<pair<long long int, long long int> > row, col;
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    a[x][y] = 1;
  }
  for (i = 1; i <= n; i++) {
    c[i] = d[i] = i;
    for (k = n; k >= 1; k--) {
      if (a[i][k] == 1) break;
    }
    row.push_back({i, k});
  }
  sort(row.begin(), row.end(), comp);
  for (i = 1; i <= n; i++) {
    if (c[i] != row[i - 1].first) {
      num = c[i];
      ind = d[row[i - 1].first];
      v.push_back({1, {i, ind}});
      srow(i, ind, n);
      c[i] = row[i - 1].first;
      c[ind] = num;
      d[num] = ind;
      d[row[i - 1].first] = i;
    }
  }
  for (i = 1; i <= n; i++) {
    for (k = 1; k <= n; k++) {
      if (a[k][i] == 1) break;
    }
    col.push_back(make_pair(k, i));
  }
  sort(col.begin(), col.end(), comp1);
  for (i = 1; i <= n; i++) {
    c[i] = d[i] = i;
  }
  for (i = 1; i <= n; i++) {
    if (c[i] != col[i - 1].second) {
      num = c[i];
      ind = d[col[i - 1].second];
      v.push_back({2, {i, ind}});
      scolumn(i, ind, n);
      c[i] = col[i - 1].second;
      c[ind] = num;
      d[num] = ind;
      d[col[i - 1].second] = i;
    }
  }
  x = v.size();
  cout << x << endl;
  for (i = 0; i <= x - 1; i++) {
    cout << v[i].first << " " << v[i].second.first << " " << v[i].second.second
         << endl;
  }
}