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 PYTHON):

Solution:
#! /Library/Frameworks/Python.framework/Versions/2.6/bin/python

import sys

class spareMatrix:
	"""custom implementation of a sparse matrix"""
	def __init__(self, N):
		self.N = N
		self.rowAdjSet = [set() for i in range(N)]
		self.colAdjSet = [set() for j in range(N)]

	def setEntry(self,i,j):
		self.rowAdjSet[i].add(j);
		self.colAdjSet[j].add(i);

	def rowEntryCount(self,i):
		return len(self.rowAdjSet[i])

	def colEntryCount(self,j):
		return len(self.colAdjSet[j])

	def colEntryCountUpTo(self,j,n):
		returnCount = 0
		for i in self.colAdjSet[j]:
			if (i < n):
				returnCount += 1
		return returnCount

	def swapRows(self,i1,i2):

		for j in self.rowAdjSet[i1]:
			self.colAdjSet[j].remove(i1)
		for j in self.rowAdjSet[i2]:
			self.colAdjSet[j].remove(i2)

		tempAdjSet = self.rowAdjSet[i1]
		self.rowAdjSet[i1] = self.rowAdjSet[i2]
		self.rowAdjSet[i2] = tempAdjSet

		for j in self.rowAdjSet[i1]:
			self.colAdjSet[j].add(i1)
		for j in self.rowAdjSet[i2]:
			self.colAdjSet[j].add(i2)

	def swapCols(self,j1,j2):

		for i in self.colAdjSet[j1]:
			self.rowAdjSet[i].remove(j1)
		for i in self.colAdjSet[j2]:
			self.rowAdjSet[i].remove(j2)

		tempAdjSet = self.colAdjSet[j1]
		self.colAdjSet[j1] = self.colAdjSet[j2]
		self.colAdjSet[j2] = tempAdjSet

		for i in self.colAdjSet[j1]:
			self.rowAdjSet[i].add(j1)
		for i in self.colAdjSet[j2]:
			self.rowAdjSet[i].add(j2)

def adjustMatrix(matrix,n,actionBank):
	if (n == 1):
		return

	t = "2 "
	# findFirstEmptyCol
	emptyColInd = n-1
	while (matrix.colEntryCountUpTo(emptyColInd,n) != 0):
		emptyColInd -= 1

	if (emptyColInd < (n-1)):
		actionBank += [t + str(emptyColInd+1) + " " + str(n)]
		matrix.swapCols(emptyColInd,n-1)
		
	t = "1 "
	# findFirstNonemptyRow
	nonEmptyRowInd = n-1
	while ((matrix.rowEntryCount(nonEmptyRowInd) == 0) & (nonEmptyRowInd > -1)):
		nonEmptyRowInd -= 1

	if (nonEmptyRowInd == -1):
		return

	if (nonEmptyRowInd < (n-1)):
		actionBank += [t + str(nonEmptyRowInd+1) + " " + str(n)]
		matrix.swapRows(nonEmptyRowInd,n-1)
		
	adjustMatrix(matrix,n-1,actionBank)

# main code of the program
actionBank = []
matrix = spareMatrix(int(raw_input()))
for n in range(matrix.N-1):
	inpPt = raw_input().split()
	i = int(inpPt[0]) - 1
	j = int(inpPt[1]) - 1
	matrix.setEntry(i,j)

sys.setrecursionlimit(1500)
adjustMatrix(matrix,matrix.N,actionBank)

print len(actionBank)
for m in range(len(actionBank)):
	print actionBank[m]

#
#
# for end of program visibility in a text editor
#
#

#
#
#
#
#