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:
//could not solve :(

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nafiur Rahman Khadem Shafin 🙂
 */
public class Main {
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader (inputStream);
		PrintWriter out = new PrintWriter (outputStream);
		TaskC solver = new TaskC ();
		solver.solve (1, in, out);
		out.close ();
	}
	
	static class TaskC {
		public void solve (int testNumber, InputReader in, PrintWriter out) {
			/*
			 * wtf? difficulty 6 😱 ? The only weak point seems to be the fact that number of '1' is <n so you can keep
			 * them on
			 * different cols or different rows if you want. I guess best will be to keep them on both different rows and
			 * differnt cols
			 * but zei duita ek row te ba ek col e ache tader jiboneo alada korte parbi na. kajei beshi paknami kore lav nai
			 * . One rough
			 * plan is to: row gulake sort kore new oi row te 1 er shonkhyar ascending order erpor col gulake sort kore new
			 * ulta vabe
			 * but the problem is when zokhon dui row ba col er shoman hobe tokhon dekha lagbe kontar shuru kothay. Even if
			 * this method
			 * is correct the biggest problem is how the hell am I gonna output the number of steps before performing the
			 * steps as string
			 * concat is very much slow. One superb way is to make an string array.
			 */
			int n = in.nextInt ();
			int[] x = new int[n+5], y = new int[n+5], cntx = new int[n+5], cnty = new int[n+5], mnx = new int[n+5], mny =
																															new int[n+
																																			5];
			for (int i = 0; i<n+4; i++) {
				Arrays.fill (mnx, Integer.MAX_VALUE);
				Arrays.fill (mny, Integer.MAX_VALUE);
			}
			for (int i = 0; i<n-1; i++) {
				x[i] = in.nextInt ();
				y[i] = in.nextInt ();
				cntx[--x[i]]++;
				cnty[--y[i]]++;
				mny[x[i]] = Math.min (mny[x[i]], y[i]);
			}
			
			int[][] mtrx = new int[n+5][n+5];
			for (int i = 0; i<n-1; i++) {
				mtrx[x[i]][y[i]] = 1;
			}
		
		/*System.out.println ("initial matrix:");
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				System.out.print (mtrx[i][j]+" ");
			}
			System.out.println ();
		}*/
			
			int ns = 0;
			String[] res = new String[100000];
			for (int i = 0; i<n-1; i++) {
				int mnidx = i;
				for (int j = i+1; j<n; j++) {
					if (cntx[j]<cntx[mnidx] || (cntx[j] == cntx[mnidx] && mny[j]<mny[mnidx])) {
//					System.out.println ("dhuksi row "+j+" "+mnidx+" "+cntx[j]+" "+cntx[mnidx]+" "+mny[j]+" "+mny[mnidx]);
						mnidx = j;
					}
				}
				if (mnidx != i) {
					cntx[i] = (cntx[i]^cntx[mnidx])^(cntx[mnidx] = cntx[i]);
					mny[i] = (mny[i]^mny[mnidx])^(mny[mnidx] = mny[i]);
					res[ns++] = ("1 "+(i+1)+" "+(mnidx+1));
					
					for (int j = 0; j<n; j++) {
						mtrx[i][j] = (mtrx[i][j]^mtrx[mnidx][j])^(mtrx[mnidx][j] = mtrx[i][j]);
					}
				}
			}
	
		/*System.out.println ("row operation shesh");
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				System.out.print (mtrx[i][j]+" ");
			}
			System.out.println ();
		}*/
			
			for (int i = 0; i<n; i++) {
				for (int j = 0; j<n; j++) {
					if (mtrx[j][i] == 1) {
						mnx[i] = j;
//					System.out.println ("mnx of "+i+": "+j);
						break;
					}
				}
			}
			
			for (int i = 0; i<n-1; i++) {
				int mxidx = i;
				for (int j = i+1; j<n; j++) {
					if (cnty[j]>cnty[mxidx] || (cnty[j] == cnty[mxidx] && mnx[j]<mnx[mxidx])) {
//					System.out.println ("dhuksi col "+j+" "+mxidx+" "+cnty[j]+" "+cnty[mxidx]+" "+mnx[j]+" "+mnx[mxidx]);
						mxidx = j;
					}
				}
				if (mxidx != i) {
					cnty[i] = (cnty[i]^cnty[mxidx])^(cnty[mxidx] = cnty[i]);
					mnx[i] = (mnx[i]^mnx[mxidx])^(mnx[mxidx] = mnx[i]);
					res[ns++] = ("2 "+(i+1)+" "+(mxidx+1));
					
					for (int j = 0; j<n; j++) {
						mtrx[j][i] = (mtrx[j][i]^mtrx[j][mxidx])^(mtrx[j][mxidx] = mtrx[j][i]);
					}
				}
			}
			out.println (ns);
			for (int i = 0; i<ns; i++) {
				out.println (res[i]);
			}
	
		/*System.out.println ("final answer");
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				System.out.print (mtrx[i][j]+" ");
			}
			System.out.println ();
		}*/
		}
		
	}
	
	static class InputReader implements AutoCloseable {
		private BufferedReader reader;
		private StringTokenizer tokenizer;
		
		public InputReader (InputStream stream) {
			reader = new BufferedReader (new InputStreamReader (stream));
			tokenizer = null;
		}
		
		public String next () {
			while (tokenizer == null || !tokenizer.hasMoreTokens ()) {
				try {
					String str;
					if ((str = reader.readLine ()) != null) tokenizer = new StringTokenizer (str);
					else return null;//to detect eof
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken ();
		}
		
		public int nextInt () {
			return Integer.parseInt (next ());
		}
		
		
		public void close () throws Exception {
			reader.close ();
		}
		
	}
}