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

public class Round162Div2 {
	public static void main(String[] args) throws IOException {
		rd = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		N = Integer.parseInt(rd.readLine());
		A = new int[N][N];
		int[][] R = new int[N][N];
		int[][] C = new int[N][N];
		for(int i=0; i<N-1; i++){
			st = new StringTokenizer(rd.readLine());
			int x = -1+Integer.parseInt(st.nextToken()), y = -1+Integer.parseInt(st.nextToken());
			A[x][y] = 1;
		}
		for(int i=0; i<N; i++){
			R[i][N-1] = (A[i][N-1]==1? 1: 0);
			for(int a=N-2; a>=0; a--) R[i][a] = R[i][a+1] + (A[i][a]==1? 1: 0);
			C[i][N-1] = (A[N-1][i]==1? 1: 0);
			for(int j=N-2; j>=0; j--) C[i][j] = C[i][j+1] + (A[j][i]==1? 1: 0);
		}
		ArrayList<String> l = new ArrayList<String>();
		X = new int[N];
		Y = new int[N];
		int[] Z = new int[N];
		int k = 0;
		int[] r = new int[N];
		int[] c = new int[N];
		for(int i=0; i<N; i++){
			r[i] = R[i][0];
			c[i] = C[i][0];
		}
		for(int i=0; i<N-1; i++){
			for(int j=i; j<N; j++){
				if(r[j]==0){
					if(j==i){
						for(int d=i; d<N; d++){
							if(c[d]!=0){
								if(d==i){
									for(int s=0; s<N; s++){
										if(A[i][s]==1) c[s]--;
										if(A[s][i]==1) r[s]--;
									}
									break;
								}
								// swap columns (i, d).
								l.add(2+" "+(i+1)+" "+(d+1));
								
								for(int s=i; s<N; s++){
									if(A[s][d]==1) r[s]--;
								}
								
								
								for(int s=0; s<N; s++){
									int z = A[s][i];
									A[s][i] = A[s][d];
									A[s][d] = z;
								}
								
								int tc = c[i]; c[i] = c[d]; c[d] = tc;
								
								for(int s=i; s<N; s++) if(A[i][s]==1) c[s]--;
								if(r[i]==0){
									
								}
								
								
								break;
							}
						}
						break;
					}
					// swap rows (i, j).
					l.add(1+" "+(i+1)+" "+(j+1));

					for(int s=i; s<N; s++){
						if(A[j][s]==1) c[s]--;
					}
					
					for(int s=0; s<N; s++){
						int z = A[i][s];
						A[i][s] = A[j][s];
						A[j][s] = z;
					}
					
					int tr = r[i]; r[i] = r[j]; r[j] = tr;
					
					for(int s=i; s<N; s++) if(A[s][i]==1) r[s]--;
					if(c[i]==0){
						// need to swap i with some column
						for(int d=i+1; d<N; d++){
							if(c[d]!=0){
								// swap cols i, d
								l.add(2+" "+(i+1)+" "+(d+1));
								X[k] = i;
								Y[k] = d;
								Z[k] = 2;
								
								for(int s=i; s<N; s++){
									if(A[s][d]==1) r[s]--;
									if(A[s][i]==1) r[s]++;
									
								}
																
								for(int s=0; s<N; s++){
									int z = A[s][i];
									A[s][i] = A[s][d];
									A[s][d] = z;
								}
								
								int tc = c[i]; c[i] = c[d]; c[d] = tc;
								break;
							}
						}
					}
					
					
					break;
				}
			}
		}
		if(2>1){
			if(A[N-1][N-1]==1){
				for(int i=0; i<N; i++){
					int c1 = 0;
					for(int j=0; j<N; j++){
						if(A[j][i]!=0) c1++;
					}
					if(c1==0){
						l.add(2+" "+(i+1)+" "+N);
						pw.println(l.size());
						for(int x=0; x<l.size(); x++) pw.println(l.get(x));
						pw.flush();
						return;
					}
				}
			}
			pw.println(l.size());
			for(int i=0; i<l.size(); i++) pw.println(l.get(i));
			pw.flush();
			return;
		}
		
		
		for(int i=0; i<N-1; i++){
			System.out.println("i: "+i);
			for(int j=i; j<N; j++){
				if(R[j][i]==0){
					if(j==i){
						System.out.println("here");
						// swap any column
						for(int d=i; d<N; d++){
							if(C[d][i]!=0){
								if(d==i) break;
								// swap d, i columns
								l.add(2+" "+(d+1)+" "+(i+1));
								System.out.println("add "+l.get(l.size()-1));
								X[k] = d;
								Y[k] = i;
								Z[k] = 2;
								int[] temp = new int[N];
								for(int z=0; z<N; z++){
									temp[z] = C[i][z];
								}
								for(int z=0; z<N; z++) C[i][z] = C[j][z];
								for(int z=0; z<N; z++) C[j][z] = temp[z];
								
								break;
							}
						}
						break;
					}
					int g = i+1, h = j+1;
					l.add(1+" "+g+" "+h);
					X[k] = i;
					Y[k] = j;
					Z[k] = 1;
					k++;
					System.out.println("add "+l.get(l.size()-1));
					int[] temp = new int[N];
					for(int x=0; x<N; x++) temp[x] = R[i][x];
					for(int x=0; x<N; x++) R[i][x] = R[j][x];
					for(int x=0; x<N; x++) R[j][x] = temp[x];
					break;
				}
			}
		}
		if(R[N-1][N-1]==1){
			for(int i=0; i<l.size(); i++){
				int a = X[i], b = Y[i];
				if(Z[i]==2){
				for(int d=0; d<N; d++){
					int temp = A[a][d];
					A[a][d] = A[b][d];
					A[b][d] = temp;
				}
				}
				else{
					for(int d=0; d<N; d++){
						int temp = A[d][a];
						A[d][a] = A[d][b];
						A[d][b] = temp;
					}
				}
			}
			for(int i=0; i<N; i++){
				int c1 = 0;
				for(int j=0; j<N; j++){
					if(A[j][i]!=0) c1++;
				}
				if(c1==0){
					l.add(2+" "+(i+1)+" "+N);
					pw.println(l.size());
					for(int x=0; x<l.size(); x++) pw.println(l.get(x));
					pw.flush();
					return;
				}
			}
		}
		pw.println(l.size());
		for(int i=0; i<l.size(); i++) pw.println(l.get(i));
		pw.flush();
	}
	
	static int N;
	static int[][] A;
	static int[] X, Y;
	
	static BufferedReader rd;
	static PrintWriter pw;
	static StringTokenizer st;
}