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

public class BelowTheDiagonal 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] row = new int[n];
		int[] uppermost = new int[n];
		int[] col = new int[n];
		
		int[] rowid = new int[n];
		int[] colid = new int[n];
		int[] newrowid = new int[n];
		int[] newcolid = new int[n];
		
		int[] inputx = new int[n-1];
		int[] inputy = new int[n-1];
		
		for(int i = 0; i < n; i++)
		{
			rowid[i] = i;
			colid[i] = i;
			newrowid[i] = i;
			newcolid[i] = i;
			uppermost[i] = -1;
		}
		
		for(int i = 0; i < n-1; i++)
		{
			int y = sc.nextInt()-1;
			int x = sc.nextInt()-1;
			
			inputx[i] = x;
			inputy[i] = y;

			row[y]++;
			col[x]++;
		}
		
		//sort rows -> banyak ke bawah
		boolean fin = false;
//		System.out.println(Arrays.toString(row));
		StringBuilder sb = new StringBuilder();
		
		int c = 0;
		
		while(!fin)
		{
			fin = true;
			for(int i = 0; i < n-1; i++)
			{
				if(row[i] > row[i+1])
				{
					int temp;
					int temp2 = rowid[i+1];
					temp = row[i+1];
					
					rowid[i+1] = rowid[i];
					rowid[i] = temp2;
					
					row[i+1] = row[i];
					row[i] = temp;
					fin = false;
//					System.out.println("DEBUG: Swap 1 " + (i+1) + " " + (i+1+1));
//					System.out.println(Arrays.toString(rowid));				
				}

			}
		}
		
		fin = false;
//		System.out.println(Arrays.toString(row));
		
		int[] curypos = new int[n]; //actual y of what used to be y=index
		for(int i = 0; i < n; i++)
		{
			curypos[rowid[i]] = i;
		}

		//recount uppermost
		for(int i = 0; i < n-1; i++)
		{
			int x = inputx[i];
			int y = inputy[i];
			
			if(uppermost[x] == -1 || uppermost[x] > curypos[y])
			{
				uppermost[x] = curypos[y];
			}
		}
		
		//set -1 to n*2
		for(int i = 0; i < n; i++)
		{
			if(uppermost[i] == -1)uppermost[i] = n*2;
		}
//		System.out.println("AA");
				
		while(!fin)
		{
			fin = true;
			for(int i = 0; i < n-1; i++)
			{
				if(uppermost[i] > uppermost[i+1])
				{
//					System.out.println("i " + i + ": " + uppermost[i] + " and " + uppermost[i+1]);
					int temp;
					int temp2 = colid[i+1];
					
//					System.out.println("Trade " + i + " " + (i+1));
					colid[i+1] = colid[i];
					colid[i] = temp2;
					
					temp = uppermost[i+1];
					uppermost[i+1] = uppermost[i];
					uppermost[i] = temp;
					fin = false;
//					sb.append("\n2 " + (i+1) + " " + (i+1+1));
				}
			}
		}
		
		
		int[] curxpos = new int[n]; //actual y of what used to be y=index
		int[] newcurxpos = new int[n]; //who has index now?
		int[] newcurypos = new int[n]; //who has index now?
		for(int i = 0; i < n; i++)
		{
			curxpos[colid[i]] = i;
			newcurxpos[i] = i;
			newcurypos[i] = i;
		}
		
//		System.out.println(Arrays.toString(rowid));
		
		for(int i = 0; i < n; i++)
		{
			//this y should be swapped with whoever has i
			
			if(newrowid[i] != rowid[i])
			{
				int tradey = newcurypos[rowid[i]];
//				System.out.println("y " + i + " has " + newrowid[i] + " instead of " + rowid[i] + ", which is at " + tradey);
				
				sb.append("\n1 " + (i+1) + " " + (tradey+1));
				c++;
				
				newcurypos[newrowid[tradey]] = i;
				
				newrowid[tradey] = newrowid[i]; //now they have this.
				newcurypos[newrowid[i]] = tradey;
				
				newrowid[i] = rowid[i];
//				System.out.println(Arrays.toString(newrowid));
			}
		}
		
//		System.out.println(Arrays.toString(newrowid));
		//
		for(int i = 0; i < n; i++)
		{
			//this y should be swapped with whoever has i
			
			if(newcolid[i] != colid[i])
			{
				int tradex = newcurxpos[colid[i]];
//				System.out.println("x " + i + " has " + newcolid[i] + " instead of " + colid[i] + ", which is at " + tradex);
				
				sb.append("\n2 " + (i+1) + " " + (tradex+1));
				c++;
				
				newcurxpos[newcolid[tradex]] = i;
				
				newcolid[tradex] = newcolid[i]; //now they have this.
				newcurxpos[newcolid[i]] = tradex;
				
				newcolid[i] = colid[i];
			}
		}
		
		/*
		System.out.println("\n");
		System.out.println(Arrays.toString(newrowid));
		System.out.println(Arrays.toString(rowid));
		System.out.println(Arrays.toString(newcolid));
		System.out.println(Arrays.toString(colid));
		*/

		
		System.out.println((Integer.toString(c)) + sb);
		
	}

}