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.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList


public class R163_Div2_C
{	
	FastReader in;
	PrintWriter out;
	
	public static void main(String[] args)  {
		new R163_Div2_C().run();
	}
	
	void run()
	{		
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}
	
    static int m = 0; // num of swaps needed
    static ArrayList<Integer> t = new ArrayList<Integer>(); // 1 = swap rows, 2 = swap cols
    static ArrayList<Integer> ii = new ArrayList<Integer>();
    static ArrayList<Integer> jj = new ArrayList<Integer>();
    
	void solve()
	{
		int n = in.nextInt();
		int[][] a = new int[n+1][n+1];
		for (int i = 0; i < n-1; i++) 
		{
			int x = in.nextInt();
			int y = in.nextInt();		
			a[x][y] = 1;
		}
		
        Solve(a, n);

        out.println(m);
        for (int i = 0; i < m; i++)
        {
        	out.println(t.get(i) + " " + (ii.get(i)) + " " + (jj.get(i)));
        }  
	}
	
    static void Solve(int[][] a, int n)
    {
        if (n == 1) return;

        //Find Column with all 0's
        int c = n, r;
        for (c = n; c > 0; c--)
        {
            boolean empty = true;
            for (r = 1; r <= n; r++)
                if (a[r][c] == 1)
                {
                    empty = false;
                    break;
                }
            if (empty) break;
        }

        //Swap column of 0's to last column
        if (c < n && c > 0)
        {
            m++;
            t.add(2);
            ii.add(c);
            jj.add(n);
            for (r = 1; r <= n; r++)
            {
                a[r][c] = a[r][n];
                a[r][n] = 0;
            }
        }

        //Find row with 1
        r = n;
        for (r = n; r > 0; r--)
        {
            boolean gotOne = false;
            for (c = 1; c <= n; c++)
                if (a[r][c] == 1)
                {
                    gotOne = true;
                    break;
                }
            if (gotOne) break;
        }

        //Swap row having 1 to lastRow
        if (r < n && r > 0)
        {
            m++;
            t.add(1);
            ii.add(r);
            jj.add(n);
            int temp;
            for (c = 1; c <= n; c++)
            {
                temp = a[r][c];
                a[r][c] = a[r][n];
                a[n][c] = temp;
            }
        }

        Solve(a, n - 1);
    }

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		} 
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}
	
	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;
	    
	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
	    
	    private String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens())
	            try {
	            	tokenizer = new StringTokenizer(br.readLine());
	            }
	            catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        return tokenizer.nextToken();
	    }
		public String nextLine() {
			try	{
				return br.readLine();
			}
			catch(Exception e) {
				throw(new RuntimeException());
			}
		}

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }	    
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}