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.io.DataInputStream;
import java.io.InputStream;



public class problem256C {
int minCount=0;
public static void main(String[] args) throws Exception{
        
        problem256C a=new problem256C();
        Parserdoubt pd=a.new Parserdoubt(System.in);
        StringBuffer sb = new StringBuffer();
        
        int n=pd.nextInt();
        int mat[][]=new int[n][n];
        int I=0,J=0;
        int arri[]=new int[n-1];
        int arrj[]=new int[n-1];
        for(int i=0;i<n-1;i++){
        I=pd.nextInt();
        J=pd.nextInt();
        arri[i]=I-1;
        arrj[i]=J-1;
        mat[I-1][J-1]=1;
            
        }
        int k=0;
    /*  for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(mat[i][j]==1&&i<j){
                mat=a.makeLead(mat, i, j, k, n,sb);
                k++;
                    
                }
                
            }
        }
        */
        
        //mat=a.diag_mat(mat, n,sb);
    //  System.out.println(a.minCount);
    //  System.out.print(sb);
        
    /*  for(int i=0;i<=n-1;i++){
            for(int j=0;j<=n-1;j++){
            System.out.print(mat[i][j]);
                
            }
            System.out.println();
        }
        
        */
        
        a.answer(mat,n,sb);
        
    /*  int [][] mat=new int[3][3];
        for(int i=0;i<2;i++){
            mat[i][i]=1;
            
        }
        a.diag_mat(mat, 3);
        
        for(int i=0;i<=2;i++){
            for(int j=0;j<=2;j++){
            System.out.print(mat[i][j]);
                
            }
            System.out.println();
        }
        */
        
}
    
    int[][] makeLead(int [][] mat,int I,int J,int K,int n,StringBuffer sb){
        
        mat=swapRow(mat,I,K,n,sb);
        mat=swapCol(mat,J,K,n,sb);  
        return mat;
    }
    
    
    void answer(int[][] mat,int n,StringBuffer sb){
        int[][] temp=mat.clone();
        for(int i=0;i<n-1;i++){
            mat=dp(mat,n-i,sb);
            if(mat==null)
                break;
            temp=mat.clone();
        }
        System.out.println(minCount);
        System.out.print(sb);
    
        
        
    }
    
    
    int[][] dp(int [][] mat,int n,StringBuffer sb){
        
        int col=choseCol(mat,n);
        if(col!=n-1)
        mat=swapCol(mat,col,n-1,n,sb);
        int row =choseRow(mat,n);
        if(row==-1){
            return null;
        }
        else{
            if(row!=n-1)
            mat=swapRow(mat,row,n-1,n,sb);
        }
        return mat;
        
        
    }
    
    int choseCol(int[][] mat,int n){
    

        for(int i=0;i<n;i++){
            boolean flag =true;
            for(int j=0;j<n;j++){
                if(mat[j][i]==1)
                flag=false;
                
            }
            if(flag)
                return i;
        }
        return -1;
        
        
    }
    
    int choseRow(int[][] mat,int n){
        
        for(int i=0;i<n;i++){
            
            for(int j=0;j<n;j++){
                if(mat[i][j]==1)
                    return i;
                
            }
        }
        return -1;
        
        
    }
    
    int[][] diag_mat(int[][] mat,int n,StringBuffer sb){
        int count=0;
        for(int i=0;i<n-1;i++){
            
        mat=    swapRow(mat,i,n-1,n,sb);
            
        }
        return mat;
    }
    
    int[][] swapCol(int [][] mat,int i,int j, int n,StringBuffer sb){
    
        int temp=0;;
        for(int k=0;k<n;k++){
            temp=mat[k][i];
            mat[k][i]=mat[k][j];
            mat[k][j]=temp;
        }
        sb.append(2+" "+(i+1)+" "+(j+1)+"\n");
        minCount++;
        return mat;

    }
    
    int[][] swapRow(int [][] mat,int i,int j, int n,StringBuffer sb){
        
        int temp=0;;
        for(int k=0;k<n;k++){
            temp=mat[i][k];
            mat[i][k]=mat[j][k];
            mat[j][k]=temp;
        }
        sb.append(1+" "+(i+1)+" "+(j+1)+"\n");
        minCount++;
        return mat;
    }
    
    class Parserdoubt
    {
       final private int BUFFER_SIZE = 1 << 17;

       private DataInputStream din;
       private byte[] buffer;
       private int bufferPointer, bytesRead;

       public Parserdoubt(InputStream in)
       {
          din = new DataInputStream(in);
          buffer = new byte[BUFFER_SIZE];
          bufferPointer = bytesRead = 0;
       }
       public String nextString() throws Exception
       {
           StringBuffer sb=new StringBuffer("");
           byte c = read();
           while (c <= ' ') c = read();
           do
           {
               sb.append((char)c);
               c=read();
           }while(c>' ');
           return sb.toString();
       }
       public char nextChar() throws Exception
       {
           byte c=read();
           while(c<=' ') c= read();
           return (char)c;
       }
       public int nextInt() throws Exception
       {
          int ret = 0;
          byte c = read();
          while (c <= ' ') c = read();
          boolean neg = c == '-';
          if (neg) c = read();
          do
          {
              ret = ret * 10 + c - '0';
             c = read();
          } while (c > ' ');
          if (neg) return -ret;
          return ret;
       }
       public long nextLong() throws Exception
       {
          long ret = 0;
          byte c = read();
          while (c <= ' ') c = read();
          boolean neg = c == '-';
          if (neg) c = read();
          do
          {
              ret = ret * 10 + c - '0';
             c = read();
          } while (c > ' ');
          if (neg) return -ret;
          return ret;
       }
       private void fillBuffer() throws Exception
       {
          bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
          if (bytesRead == -1) buffer[0] = -1;
       }

       private byte read() throws Exception
       {
          if (bufferPointer == bytesRead) fillBuffer();
          return buffer[bufferPointer++];
       }
    }   
}