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 JAVA):

Solution:

import java.util.*;
import java.io.*;
public class Main {
    public static long time = 0;
    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();
        
        IN = System.in;
        OUT = System.out;
        in = new BufferedReader(new InputStreamReader(IN));
        out = new PrintWriter(OUT, FLUSH);
        solveOne();
        out.flush();
    }
    
    public static void solveOne() throws Exception {
        int n1 = ni();
        int[][] pointList = new int[n1 - 1][2];
        for (int i = 0 ; i < n1 - 1; i++){
            pointList[i][0] = ni() - 1;
            pointList[i][1] = ni() - 1;
        }
        
//      printMatrix(pointList, n1);
        
        final int[] maxStretch = new int[n1];
        Integer[] order = new Integer[n1];
        StringBuilder fin = new StringBuilder();
        int cmdCount = 0;
        int[] newLocation = new int[n1];
        int[] curIndex = new int[n1];
        int[] curValue = new int[n1];
        for (int qq = 0; qq < 10;qq ++){
            // swap rows
            Arrays.fill(maxStretch, -1);
            for (int[] e: pointList){
                if (e[1] > maxStretch[e[0] ]){
                    maxStretch[e[0]] = e[1];
                }
            }
            for (int i = 0; i < n1; i++){
                order[i] = i;
            }
//          px(maxStretch);
//          px(order);
            Arrays.sort(order, new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return maxStretch[o1] - maxStretch[o2];
                }
            });
            for (int i = 0 ; i < n1; i++){
                curIndex[i] = i;
                curValue[i] = i;
            }
            for (int i = 0; i < n1; i++){
                newLocation[order[i]] = i;
                if (curIndex[order[i]] != i){
//                  pn(1, i, newLocation[order[i]] );
                    fin.append("1 "+ (i + 1) + " " + (curIndex[order[i]] + 1) + "\n");
                    
                    int toValue = curValue[i];
                    swap(curValue, i, curIndex[order[i]]);
                    swap(curIndex, order[i],toValue);
                    cmdCount++;
                }
            }
            for (int[] e: pointList){
                e[0] = newLocation[e[0]];
            }
            // swap columns
            Arrays.fill(maxStretch, n1);
            for (int[] e: pointList){
                if (e[0] < maxStretch[e[1] ]){
                    maxStretch[e[1]] = e[0];
                }
            }
            for (int i = 0; i < n1; i++){
                order[i] = i;
            }
//          px(maxStretch);
//          px(order);
            Arrays.sort(order, new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return maxStretch[o1] - maxStretch[o2];
                }
            });
            for (int i = 0 ; i < n1; i++){
                curIndex[i] = i;
                curValue[i] = i;
            }
            for (int i = 0; i < n1; i++){
                newLocation[order[i]] = i;
                if (curIndex[order[i]] != i){
//                  pn(1, i, newLocation[order[i]] );
                    fin.append("2 "+ (i + 1) + " " + (curIndex[order[i]] + 1) + "\n");
                    
                    int toValue = curValue[i];
                    swap(curValue, i, curIndex[order[i]]);
                    swap(curIndex, order[i],toValue);
                    cmdCount++;
                }
            }
            for (int[] e: pointList){
                e[1] = newLocation[e[1]];
            }
        }
//      printMatrix(pointList, n1);
        pn(cmdCount);
        pn(fin);
    }
    public static void swap(int[] l1, int a, int b){
        int temp = l1[a];
        l1[a] = l1[b];
        l1[b] = temp;
    }
    public static void printMatrix(int[][] pointList, int n1){
        int[][] mat = new int[n1][n1];
        for (int[] e: pointList){
            mat[e[0]][e[1]] = 1;
        }
        for (int[] e: mat){
            px(e);
        }
        px();
    }
    
    public static void solveTwo() throws Exception {
        
    }
    
    public static void solveThree() throws Exception {
        
    }
    
    public static BufferedReader in;
    public static StringTokenizer st;
    public static InputStream IN;
    public static OutputStream OUT;
    public static String nx() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            String k1 = in.readLine();
            if (k1 == null) return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }
    public static int ni () throws Exception {
        return Integer.parseInt(nx());
    }
    public static long nl() throws Exception{
        return Long.parseLong(nx());
    }
    public static double nd() throws Exception{
        return Double.parseDouble(nx());
    }
    public static void px(Object ... l1){
        System.out.println(Arrays.deepToString(l1));
    }
    public static boolean FLUSH = false;
    public static PrintWriter out;
    public static void p(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
    }
    public static void pn(Object ... l1){
        for (int i = 0; i < l1.length; i++){
            if (i != 0) out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }
    
    public static void pn(Collection l1){
        boolean first = true;
        for (Object e: l1){
            if (first) first = false;
            else out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}