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;
import java.util.Arrays;

public class C {
    
    static int count = 0;
    static StringBuffer sb;
    static int[][] matrix;
    public static void main(String[] args) throws Exception {
        C obj = new C();
        Parsedoubt in = obj.new Parsedoubt(System.in);
        sb = new StringBuffer();

        int n = in.nextInt();

        solve(sb, n , in);


        System.out.println(sb);

    }
    
    public static void solve(StringBuffer sb, int n, Parsedoubt in) throws Exception {
    
        matrix = new int[n+1][n+1];
        
        int[] row = new int[n+1];
        int[] col = new int[n+1];

        for(int j=1; j<n; j++){
          
            int m = in.nextInt();
            int l = in.nextInt();
      
            matrix[m][l] = 1;
            
            row[m]++; 
            col[l]++; 
        }
        
       count_ans(n , row, col); 
       System.out.println(count);
    }
    
    public static void count_ans(int n , int[] row, int[] col){
             
          if(n == 1) 
              return;
        
           int min = getmin(col , n);
           col[min] = col[n];
           swap_cols(min, n); 
           if(min!=n){
           count++;
           sb.append("2 " + min + " " + n + "\n"); }
           
           
           
           int r = findrow(row , n);
           if( r==-1)
               return;
           if(r != n){
           count++;
           sb.append("1 " + r + " " + n + "\n");
           row[r] = row[n];
           }
           int[] temp = Arrays.copyOf(matrix[r],n+1);
           
           swap_rows(r, n);
           
           for(int i=1; i<=n; i++){
             if(temp[i] == 1){
               col[i]--;
             }
             
           }
           
           
           
           count_ans(n-1 , row, col); 
    }
    
    public static int getmin(int[] col, int till){
     
        int min = 1; 
        for(int j=2; j<=till; j++){
          if(col[min] > col[j])
              min = j;
        }
        return min;
    }
    
    public static void swap_cols(int a , int b){
        
        for(int j=1; j<=b; j++){
         matrix[j][a] = matrix[j][b];
         }
    }
    
    public static void swap_rows(int a , int b){
        
        for(int j=1; j<=b; j++){
         matrix[a][j] = matrix[b][j];
         }
    }
    
     public static int findrow(int[] row, int till){
        
        for(int i=1; i<=till; i++){
          if(row[i] > 0){
            return i;
          }
        }
        return -1;
    }

  /*  public static void solve(StringBuffer sb, int n, Parsedoubt in) throws Exception {
        
        int[][] matrix = new int[n+1][n+1];
        
        int[] row = new int[n+1];
        int[] col = new int[n+1];

        for(int j=1; j<n; j++){
          
            int m = in.nextInt();
            int l = in.nextInt();
      
            matrix[m][l] = 1;
            
            row[m]++; 
            col[l]++; 
        }
        
        int count = 0;
        
        for(int i=0; i<n-1; i++){
            
           int min = getmin(col , n-i);
           count++;
           setup_col(min , n-i , col);
           sb.append("2 " + min + " " + (n-i) + "\n"); 
           int r = findrow(row , n-i);
           if( r==-1)
               break;
           count++;
           sb.append("1 " + r + " " + (n-i) + "\n");
           int temp = row[r];
           row[r] = row[n-i];
           row[n-i] = row[r];
           
           
        }
        
        System.out.println(count);
    }
    
    public static void setup_col(int r, int[] row){
           
          
    }
    
    public static int getmin(int[] col, int till){
     
        int min = 1; 
        for(int j=2; j<=till; j++){
          if(col[min] < col[j])
              min = j;
        }
        col[min] = col[till];
        return min;
    }
    
    public static int findrow(int[] row, int till){
        
        for(int i=1; i<=till; i++){
          if(row[i] > 0){
            return i;
          }
        }
        return -1;
    }
*/
    class Parsedoubt {

        final private int BUFFER_SIZE = 1 << 17;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Parsedoubt(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++];
        }
    }
}