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.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;


public class CodeforcesR163Div2C {

	public static int[] parseNumbers(String line, int n) {
		int[] numbers = new int[n];
		boolean[] isNeg = new boolean[n];
		int idx = 0;
		for(int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			if(Character.isDigit(c))
				numbers[idx] = 10 * numbers[idx] + (c - '0');
			else if(c == ' ')
				idx++;
			else
				isNeg[idx] = true;
		}
		
		for(int i = 0; i < n; i++)
			if(isNeg[i]) numbers[i] *= -1;
		
		return numbers;
	}
	
	public static long[] parseNumbersL(String line, int n) {
		long[] numbers = new long[n];
		boolean[] isNeg = new boolean[n];
		int idx = 0;
		for(int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			if(Character.isDigit(c))
				numbers[idx] = 10L * numbers[idx] + (c - '0');
			else if(c == ' ')
				idx++;
			else
				isNeg[idx] = true;
		}
		
		for(int i = 0; i < n; i++)
			if(isNeg[i]) numbers[i] *= -1;
		
		return numbers;
	}
	
	private static class Pair implements Comparable<Pair>{
		int first;
		int second;
		public Pair(int[] in) {
			this.first = in[0];
			this.second = in[1];
		}
		public Pair(int x, int y) {
			this.first = x;
			this.second = y;
		}
		
		public int compareTo(Pair o) {
			if(first == o.first) return second - o.second;
			return first - o.first;
		}
	}
	
	public static int N;
	public static int[][] m;
	
	public static void swapRow(int row1, int row2) {
		for(int i = 0; i < N; i++) {
			int t = m[row1][i];
			m[row1][i] = m[row2][i];
			m[row2][i] = t;
		}
	}
	
	public static void swapCol(int col1, int col2) {
		for(int i = 0; i < N; i++) {
			int t = m[i][col1];
			m[i][col1] = m[i][col2];
			m[i][col2] = t;
		}
	}
		
	public static void main(String[] args) throws Exception {
		final String ROW = "1", COL = "2";
		
//		System.setIn(new FileInputStream("CodeforcesR163Div2C.in"));
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		N = Integer.parseInt(bf.readLine().trim());
		int[] rowCount = new int[N], colCount = new int[N];
		m = new int[N][N];
		for(int i = 0; i < N - 1; i++) {			
			int in[] = parseNumbers(bf.readLine().trim(), 2);
			int x = in[0] - 1;
			int y = in[1] - 1;
			rowCount[x]++;
			colCount[y]++;
			m[x][y] = 1;
		}
		int steps = 0;
		StringBuilder sb = new StringBuilder();
		
		for(int row = N - 1; row > 0; row--) {
			int lastCol = row;
			if(colCount[lastCol] > 0) {
				for(int col = 0; col < lastCol; col++) {
					if(colCount[col] > 0) continue;
					
					colCount[col] = colCount[lastCol];
					colCount[lastCol] = 0;
					swapCol(col, lastCol);
						
					steps++;
					sb.append(COL + " " + (lastCol + 1) + " " + (col + 1));
					sb.append("\n");
					break;
				}
			}
			
			if(rowCount[row] == 0) {
				for(int r = 0; r < row; r++) {
					if(rowCount[r] == 0) continue;
					
					rowCount[row] = rowCount[r];
					rowCount[r] = 0;
					swapRow(row, r);
					
					steps++;
					sb.append(ROW + " " + (r + 1) + " " + (row + 1));
					sb.append("\n");
					break;
				}
			}
			
			for(int i = 0; i < N; i++)
				colCount[i] -= m[row][i];
		}
		
		System.out.println(steps);
		System.out.print(sb);
		
	}

}