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]]++;
				mnx[y[i]] = Math.min (mnx[y[i]], x[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;
		}
		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 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));
				}
			}
			out.println (ns);
			for (int i = 0; i<ns; i++) {
				out.println (res[i]);
			}
		}

	}

	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 ();
		}

	}
}


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[] inputx = new int[n-1];
		int[] inputy = new int[n-1];

		for(int i = 0; i < n; i++)
		{
			rowid[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;
					sb.append("\n1 " + (i+1) + " " + (i+1+1));
					c++;
				}
			}
		}

		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;
					temp = uppermost[i+1];
					uppermost[i+1] = uppermost[i];
					uppermost[i] = temp;
					fin = false;
					sb.append("\n2 " + (i+1) + " " + (i+1+1));
					c++;
				}
			}
		}

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

	}

}


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[] col = new int[n];

//		for(int i = 0; i < n; i++)
		{
//			row[i] = sc.nextInt();
		}

		for(int i = 0; i < n-1; i++)
		{
			row[sc.nextInt()-1]++;
			col[sc.nextInt()-1]++;
		}

		//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;
					temp = row[i+1];
					row[i+1] = row[i];
					row[i] = temp;
					fin = false;
					sb.append("\n1 " + (i+1) + " " + (i+1+1));
					c++;
				}
			}
		}

		fin = false;
//		System.out.println(Arrays.toString(row));

		while(!fin)
		{
			fin = true;
			for(int i = 0; i < n-1; i++)
			{
				if(col[i] < col[i+1])
				{
					int temp;
					temp = col[i+1];
					col[i+1] = col[i];
					col[i] = temp;
					fin = false;
					sb.append("\n2 " + (i+1) + " " + (i+1+1));
					c++;
				}
			}
		}

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

	}

}


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;
//					sb.append("\n1 " + (i+1) + " " + (i+1+1));
				}
			}
		}

		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;
		}

		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[i] = tradey;

				newrowid[i] = rowid[i];
			}
		}
		//
		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[newrowid[tradex]] = i;

				newcolid[tradex] = newcolid[i]; //now they have this.
				newcurxpos[i] = tradex;

				newcolid[i] = colid[i];
			}
		}

//		System.out.println(Arrays.toString(colid));

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

	}

}


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;
//					sb.append("\n1 " + (i+1) + " " + (i+1+1));
					c++;
				}
			}
		}

		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));
					c++;
				}
			}
		}

		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[colid[i]] = i;
			newcurypos[colid[i]] = i;
		}

		for(int i = 0; i < n; i++)
		{
			//this y should be swapped with whoever has i

			if(newrowid[i] != rowid[i])
			{
//				System.out.println("y " + i + " has " + newrowid[i] + " instead of " + rowid[i]);
				int tradey = newcurypos[i];

				sb.append("\n1 " + (i+1) + " " + (tradey+1));

				newcurypos[i] = i;

				newrowid[tradey] = newrowid[i]; //now they have this.
				newcurypos[newrowid[tradey]] = tradey;

				newrowid[i] = rowid[i];
			}
		}
		//
		for(int i = 0; i < n; i++)
		{
			//this y should be swapped with whoever has i

			if(newcolid[i] != colid[i])
			{
//				System.out.println("y " + i + " has " + newcolid[i] + " instead of " + colid[i]);
				int tradex = newcurxpos[i];

				sb.append("\n2 " + (i+1) + " " + (tradex+1));

				newcurxpos[i] = i;

				newcolid[tradex] = newcolid[i]; //now they have this.
				newcurxpos[newrowid[tradex]] = tradex;

				newcolid[i] = colid[i];
			}
		}

//		System.out.println(Arrays.toString(colid));

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

	}

}


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);

	}

}


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[newrowid[tradex]] = i;

				newcolid[tradex] = newcolid[i]; //now they have this.
				newcurxpos[newcolid[i]] = tradex;

				newcolid[i] = colid[i];
			}
		}

//		System.out.println(Arrays.toString(colid));

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

	}

}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader in = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args)
    {
        solve();
        out.close();
    }

    private static void solve()
    {
        int n = in.nextInt();

        int[][] mat = new int[n][n];
        for (int i = 0; i < n - 1; i++)
            mat[in.nextInt() - 1][in.nextInt() - 1] = 1;

        int count = 0;
        StringBuilder answer = new StringBuilder();

        int left = 0;
        // Find the column(s) that are empty and move them to the far right
        for (int c = 0; c < n; c++)
        {
            boolean empty = true;
            for (int r = 0; r < n; r++)
            {
                if (mat[r][c] == 1)
                    empty = false;
            }

            if (!empty && left != c)
            {
                count++;
                answer.append(2 + " " + (c + 1) + " " + (left + 1) + "\n");
                swap(mat, 2, c, left);
            }
            if (!empty)
                left++;
        }

        int down = n - 1;
        // Find the row(s) that are empty and move them to the far top
        for (int r = n - 1; r >= 0; r--)
        {
            boolean empty = true;
            for (int c = 0; c < n; c++)
            {
                if (mat[r][c] == 1)
                    empty = false;
            }

            if (!empty && r != down)
            {
                count++;
                answer.append(1 + " " + (r + 1) + " " + (down + 1) + "\n");
                swap(mat, 1, r, down);
            }

            if (!empty)
                down--;

        }

//        for (int[] row : mat)
//            out.println(Arrays.toString(row));

        left = 0;
        for (int r = 0; r < n; r++)
        {
            for (int c = 0; c < n; c++)
            {
                if (c < left)
                    continue;

                if (mat[r][c] == 1)
                {
                    if (c != left)
                    {
                        count++;
                        answer.append(2 + " " + (c + 1) + " " + (left + 1) + "\n");
                        swap(mat, 2, c, left);
                    }
                    left++;
                }
            }
        }
        out.println(count);
        out.print(answer);

//        for (int[] row : mat)
//            out.println(Arrays.toString(row));
    }

    private static void swap(int[][] mat, int t, int a, int b)
    {
        if (t == 1)
        {
            int[] oldA = new int[mat.length];
            System.arraycopy(mat[a], 0, oldA, 0, mat.length);
            System.arraycopy(mat[b], 0, mat[a], 0, mat.length);
            System.arraycopy(oldA, 0, mat[b], 0, mat.length);
        }
        else
        {
            for (int r = 0; r < mat.length; r++)
            {
                int temp = mat[r][a];
                mat[r][a] = mat[r][b];
                mat[r][b] = temp;
            }
        }
    }

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] colTotal = new int[n];
        int[] rowTotal = new int[n];
        boolean[][] g = new boolean[n][n];
        for (int k = 0; k < n - 1; k++) {
            int i = in.nextInt() - 1;
            int j = in.nextInt() - 1;
            rowTotal[i]++;
            colTotal[j]++;
            g[i][j] = true;
        }
        List<Integer> answer = new ArrayList<Integer>();
        int[] colMinPos = new int[n];
        Arrays.fill(colMinPos, Integer.MAX_VALUE);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    colMinPos[j] = Math.min(colMinPos[j], i);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (colTotal[j] > colTotal[i2] || (colTotal[j] == colTotal[i2] && colMinPos[j] < colMinPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(2);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = colTotal[i2];
                colTotal[i2] = colTotal[i];
                colTotal[i] = t;
                t = colMinPos[i2];
                colMinPos[i2] = colMinPos[i];
                colMinPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[j][i];
                    g[j][i] = g[j][i2];
                    g[j][i2] = v;
                }
            }
        }
        int[] rowMaxPos = new int[n];
        Arrays.fill(rowMaxPos, -1);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    rowMaxPos[i] = Math.max(rowMaxPos[i], j);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (rowTotal[j] < rowTotal[i2] || (rowTotal[j] == rowTotal[i2] && rowMaxPos[j] < rowMaxPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(1);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = rowTotal[i2];
                rowTotal[i2] = rowTotal[i];
                rowTotal[i] = t;
                t = rowMaxPos[i2];
                rowMaxPos[i2] = rowMaxPos[i];
                rowMaxPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[i][j];
                    g[i][j] = g[i2][j];
                    g[i2][j] = v;
                }
            }
        }
        Arrays.fill(colMinPos, Integer.MAX_VALUE);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    colMinPos[j] = Math.min(colMinPos[j], i);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (colTotal[j] > colTotal[i2] || (colTotal[j] == colTotal[i2] && colMinPos[j] < colMinPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(2);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = colTotal[i2];
                colTotal[i2] = colTotal[i];
                colTotal[i] = t;
                t = colMinPos[i2];
                colMinPos[i2] = colMinPos[i];
                colMinPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[j][i];
                    g[j][i] = g[j][i2];
                    g[j][i2] = v;
                }
            }
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int row = 0;
            int maxi = -1;
            for (int j = 0; j < n; j++)
                if (g[i][j]) {
                    sum++;
                    row++;
                    maxi = j;
                }
            if (row != rowTotal[i])
                throw new RuntimeException();
        }
        if (sum != n - 1)
            throw new RuntimeException();
        for (int i = 0; i < n; i++) {
            int col = 0;
            int mini = Integer.MAX_VALUE;
            for (int j = n - 1; j >= 0; j--)
                if (g[j][i]) {
                    col++;
                    mini = j;
                }
            if (col != colTotal[i] || mini != colMinPos[i])
                throw new RuntimeException();
        }
        out.println(answer.size() / 3);
        for (int i = 0; i < answer.size(); i += 3)
            out.println(answer.get(i) + " " + answer.get(i + 1) + " " + answer.get(i + 2));
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] colTotal = new int[n];
        int[] rowTotal = new int[n];
        boolean[][] g = new boolean[n][n];
        for (int k = 0; k < n - 1; k++) {
            int i = in.nextInt() - 1;
            int j = in.nextInt() - 1;
            rowTotal[i]++;
            colTotal[j]++;
            g[i][j] = true;
        }
        List<Integer> answer = new ArrayList<Integer>();
        int[] colMinPos = new int[n];
        Arrays.fill(colMinPos, Integer.MAX_VALUE);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    colMinPos[j] = Math.min(colMinPos[j], i);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (colTotal[j] > colTotal[i2] || (colTotal[j] == colTotal[i2] && colMinPos[j] < colMinPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(2);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = colTotal[i2];
                colTotal[i2] = colTotal[i];
                colTotal[i] = t;
                t = colMinPos[i2];
                colMinPos[i2] = colMinPos[i];
                colMinPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[j][i];
                    g[j][i] = g[j][i2];
                    g[j][i2] = v;
                }
            }
        }
        int[] rowMaxPos = new int[n];
        Arrays.fill(rowMaxPos, -1);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    rowMaxPos[i] = Math.max(rowMaxPos[i], j);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (rowTotal[j] < rowTotal[i2] || (rowTotal[j] == rowTotal[i2] && rowMaxPos[j] < rowMaxPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(1);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = rowTotal[i2];
                rowTotal[i2] = rowTotal[i];
                rowTotal[i] = t;
                t = rowMaxPos[i2];
                rowMaxPos[i2] = rowMaxPos[i];
                rowMaxPos[i] = t;
            }
        }
        out.println(answer.size() / 3);
        for (int i = 0; i < answer.size(); i += 3)
            out.println(answer.get(i) + " " + answer.get(i + 1) + " " + answer.get(i + 2));
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] colTotal = new int[n];
        int[] rowTotal = new int[n];
        boolean[][] g = new boolean[n][n];
        for (int k = 0; k < n - 1; k++) {
            int i = in.nextInt() - 1;
            int j = in.nextInt() - 1;
            rowTotal[i]++;
            colTotal[j]++;
            g[i][j] = true;
        }
        List<Integer> answer = new ArrayList<Integer>();
        int[] colMinPos = new int[n];
        Arrays.fill(colMinPos, Integer.MAX_VALUE);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    colMinPos[j] = Math.min(colMinPos[j], i);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (colTotal[j] > colTotal[i2] || (colTotal[j] == colTotal[i2] && colMinPos[j] < colMinPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(2);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = colTotal[i2];
                colTotal[i2] = colTotal[i];
                colTotal[i] = t;
                t = colMinPos[i2];
                colMinPos[i2] = colMinPos[i];
                colMinPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[j][i];
                    g[j][i] = g[j][i2];
                    g[j][i2] = v;
                }
            }
        }
        int[] rowMaxPos = new int[n];
        Arrays.fill(rowMaxPos, -1);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    rowMaxPos[i] = Math.max(rowMaxPos[i], j);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (rowTotal[j] < rowTotal[i2] || (rowTotal[j] == rowTotal[i2] && rowMaxPos[j] < rowMaxPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(1);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = rowTotal[i2];
                rowTotal[i2] = rowTotal[i];
                rowTotal[i] = t;
                t = rowMaxPos[i2];
                rowMaxPos[i2] = rowMaxPos[i];
                rowMaxPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[i][j];
                    g[i][j] = g[i2][j];
                    g[i2][j] = v;
                }
            }
        }
        Arrays.fill(colMinPos, Integer.MAX_VALUE);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (g[i][j])
                    colMinPos[j] = Math.min(colMinPos[j], i);
        for (int i = 0; i < n; i++) {
            int i2 = i;
            for (int j = i + 1; j < n; j++)
                if (colTotal[j] > colTotal[i2] || (colTotal[j] == colTotal[i2] && colMinPos[j] < colMinPos[i2]))
                    i2 = j;
            if (i2 != i) {
                answer.add(2);
                answer.add(i + 1);
                answer.add(i2 + 1);
                int t = colTotal[i2];
                colTotal[i2] = colTotal[i];
                colTotal[i] = t;
                t = colMinPos[i2];
                colMinPos[i2] = colMinPos[i];
                colMinPos[i] = t;
                for (int j = 0; j < n; j++) {
                    boolean v = g[j][i];
                    g[j][i] = g[j][i2];
                    g[j][i2] = v;
                }
            }
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int row = 0;
            int maxi = -1;
            for (int j = 0; j < n; j++)
                if (g[i][j]) {
                    sum++;
                    row++;
                    maxi = j;
                }
            if (row != rowTotal[i] || maxi != rowMaxPos[i])
                throw new RuntimeException();
        }
        if (sum != n - 1)
            throw new RuntimeException();
        for (int i = 0; i < n; i++) {
            int col = 0;
            int mini = Integer.MAX_VALUE;
            for (int j = n - 1; j >= 0; j--)
                if (g[j][i]) {
                    col++;
                    mini = j;
                }
            if (col != colTotal[i] || mini != colMinPos[i])
                throw new RuntimeException();
        }
        out.println(answer.size() / 3);
        for (int i = 0; i < answer.size(); i += 3)
            out.println(answer.get(i) + " " + answer.get(i + 1) + " " + answer.get(i + 2));
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
}


import java.io.*;
import java.util.*;

public class C
{
    InputReader in;
    PrintWriter out;

    void run() throws IOException
    {
        in = new InputReader(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    public static void main(String[] args) throws IOException
    {
        new C().run();
    }
    int a[][],n;
    int cols[], rows[]; //count of no of 1's
    StringBuilder ans;
    int numOps;
    void solve() throws IOException
    {
        n = in.readInt();
        a = new int[n][n];
        cols = new int[n];
        rows = new int[n];
        for (int i = 0; i < n-1; i++)
        {
            int x = in.readInt()-1;
            int y = in.readInt()-1;
            a[x][y] = 1;
            cols[y]++;
            rows[x]++;
        }
        ans = new StringBuilder();
        func(n);
        out.println(numOps);
        out.println(ans);
    }

    private void func(int n)
    {
        if(n==1)
            return;

        //now n-1 1's therefore at least 1 col with no 1, we put it at the last
        //definitely swap will occur
        for (int i = 0; i < n-1; i++)
        {
            if(cols[i]==0)
            {
                //swap ith col with nth col
                ans.append("2 "+(i+1)+" "+n+"\n");
                numOps++;
                swapCol(i,n-1);
                break;
            }
        }
//        for (int i = 0; i < n; i++)
//        {
//            out.print(Arrays.toString(a[i]));
//            out.println(" "+rows[i]+" "+cols[i]);
//        }
        //place a row containing any 1 at the end row(if one exists)
        //if swap doesnt occur we swap nth row with itself
        for (int i = 0; i < n-1; i++)
        {
            if(rows[i]>0)
            {
                //swap ith row with nth row
                ans.append("1 "+(i+1)+" "+n+"\n");
                numOps++;
                swapRow(i,n-1);
                break;
            }
        }
//        for (int i = 0; i < n; i++)
//        {
//            out.print(Arrays.toString(a[i]));
//            out.println(" "+rows[i]+" "+cols[i]);
//        }
        //now problem reduced to n-1 dimension
        //since the nth row and nth col are now not part of the board, adjust cols and rows array
        for (int i = 0; i < n; i++)
        {
            if(a[n-1][i]==1)
                cols[i]--;
            if(a[i][n-1]==1)
                rows[i]--;
        }
        func(n-1);
    }

    private void swapRow(int i, int j)
    {
        int t = rows[i];
        rows[i] = rows[j];
        rows[j] = t;

        int t2[] = a[i];
        a[i] = a[j];
        a[j] = t2;
    }

    private void swapCol(int i, int j)
    {
        int t = cols[i];
        cols[i] = cols[j];
        cols[j] = t;

        for (int ix = 0; ix < n; ix++)
        {
            int t2 = a[ix][i];
            a[ix][i] = a[ix][j];
            a[ix][j] = t2;
        }
    }
}

class InputReader
{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read(buf);
            }
            catch (IOException e)
            {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do
        {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public Long readLong()
    {
        return Long.parseLong(readString());
    }

    public Double readDouble()
    {
        return Double.parseDouble(readString());
    }

    public static boolean isSpaceChar(int c)
    {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
}


import java.io.*;
import java.util.*;

public class C
{
    InputReader in;
    PrintWriter out;

    void run() throws IOException
    {
        in = new InputReader(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    public static void main(String[] args) throws IOException
    {
        new C().run();
    }
    int a[][],n;
    int cols[], rows[]; //count of no of 1's
    void solve() throws IOException
    {
        n = in.readInt();
        a = new int[n][n];
        cols = new int[n];
        rows = new int[n];
        for (int i = 0; i < n-1; i++)
        {
            int x = in.readInt()-1;
            int y = in.readInt()-1;
            a[x][y] = 1;
            cols[y]++;
            rows[x]++;
        }
        out.println((n-1)*2);
        func(n);
    }

    private void func(int n)
    {
        if(n==1)
            return;

        //now n-1 1's therefore at least 1 col with no 1, we put it at the last
        //definitely swap will occur
        for (int i = 0; i < n; i++)
        {
            if(cols[i]==0)
            {
                //swap ith col with nth col
                out.println("2 "+(i+1)+" "+n);
                swapCol(i,n-1);
                break;
            }
        }
//        for (int i = 0; i < n; i++)
//        {
//            out.print(Arrays.toString(a[i]));
//            out.println(" "+rows[i]+" "+cols[i]);
//        }
        //place a row containing any 1 at the end row(if one exists)
        //if swap doesnt occur we swap nth row with itself
        for (int i = 0; i < n-1; i++)
        {
            if(rows[i]>0)
            {
                //swap ith row with nth row
                out.println("1 "+(i+1)+" "+n);
                swapRow(i,n-1);
                break;
            }
            if(i==n-2) //no swap possible , swap nth row with itself
            {
                out.println("1 "+ n +" "+n);
            }
        }
//        for (int i = 0; i < n; i++)
//        {
//            out.print(Arrays.toString(a[i]));
//            out.println(" "+rows[i]+" "+cols[i]);
//        }
        //now problem reduced to n-1 dimension
        //since the nth row and nth col are now not part of the board, adjust cols and rows array
        for (int i = 0; i < n; i++)
        {
            if(a[n-1][i]==1)
                cols[i]--;
            if(a[i][n-1]==1)
                rows[i]--;
        }
        func(n-1);
    }

    private void swapRow(int i, int j)
    {
        int t = rows[i];
        rows[i] = rows[j];
        rows[j] = t;

        int t2[] = a[i];
        a[i] = a[j];
        a[j] = t2;
    }

    private void swapCol(int i, int j)
    {
        int t = cols[i];
        cols[i] = cols[j];
        cols[j] = t;

        for (int ix = 0; ix < n; ix++)
        {
            int t2 = a[ix][i];
            a[ix][i] = a[ix][j];
            a[ix][j] = t2;
        }
    }
}

class InputReader
{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream)
    {
        this.stream = stream;
    }

    public int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars)
        {
            curChar = 0;
            try
            {
                numChars = stream.read(buf);
            }
            catch (IOException e)
            {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-')
        {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do
        {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString()
    {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do
        {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public Long readLong()
    {
        return Long.parseLong(readString());
    }

    public Double readDouble()
    {
        return Double.parseDouble(readString());
    }

    public static boolean isSpaceChar(int c)
    {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
}


import java.util.*;
import java.io.*;

public class Main{

	public void run(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean g[][] = new boolean[n][n];
		for(int i=0;i<n-1;i++){
			int x = in.nextInt()-1;
			int y = in.nextInt()-1;
			g[x][y] = true;
		}

		int row[] = new int[n];
		int col[] = new int[n];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				row[i]+=g[i][j] ? 1 : 0;
			}
		}

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				col[i]+=g[j][i] ? 1 : 0;
			}
		}
		//System.out.println(Arrays.toString(row));
		//System.out.println(Arrays.toString(col));

		ArrayList<int[]> ans = new ArrayList<int[]>();
		for(int l = 0; l < n; l++){
			if (row[l] > 0) {
				for(int i=l+1;i<n;i++){
					if (row[i] == 0) {
						ans.add(new int[]{1, l + 1, i + 1});
						for(int k=0;k<n;k++){
							boolean d = g[l][k];g[l][k] = g[i][k];g[i][k] = d;
						}
						row[i] = row[l];
						row[l] = 0;
					}
				}
			}

			if (col[l] == 0){
				for(int i=l+1;i<n;i++){
					if (col[i] > 0) {
						ans.add(new int[]{2, l + 1, i + 1});
						for(int k=0;k<n;k++){
							boolean d = g[k][l];g[k][l] = g[k][i];g[k][i] = d;
						}
						col[l] = col[i];
						col[i] = 0;
					}
				}
			}

			for(int i=0;i<n;i++){
				if (g[i][l]){
					row[i]--;
				}
			}
		}

		System.out.println(ans.size());
		for(int[] i : ans)
			System.out.println(i[0] + " " + i[1] + " " + i[2]);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


import java.util.*;
import java.io.*;

public class Main{

	public void run(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		boolean g[][] = new boolean[n][n];
		for(int i=0;i<n-1;i++){
			int x = in.nextInt()-1;
			int y = in.nextInt()-1;
			g[x][y] = true;
		}

		int row[] = new int[n];
		int col[] = new int[n];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				row[i]+=g[i][j] ? 1 : 0;
			}
		}

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				col[i]+=g[j][i] ? 1 : 0;
			}
		}
		//System.out.println(Arrays.toString(row));
		//System.out.println(Arrays.toString(col));

		ArrayList<int[]> ans = new ArrayList<int[]>();
		for(int l = 0; l < n; l++){
			if (row[l] > 0) {
				for(int i=l+1;i<n;i++){
					if (row[i] == 0) {
						ans.add(new int[]{1, l + 1, i + 1});
						for(int k=0;k<n;k++){
							boolean d = g[l][k];g[l][k] = g[i][k];g[i][k] = d;
						}
						row[i] = row[l];
						row[l] = 0;
						break;
					}
				}
			}

			if (col[l] == 0){
				for(int i=l+1;i<n;i++){
					if (col[i] > 0) {
						ans.add(new int[]{2, l + 1, i + 1});
						for(int k=0;k<n;k++){
							boolean d = g[k][l];g[k][l] = g[k][i];g[k][i] = d;
						}
						col[l] = col[i];
						col[i] = 0;
						break;
					}
				}
			}

			for(int i=0;i<n;i++){
				if (g[i][l]){
					row[i]--;
				}
			}
		}

		System.out.println(ans.size());
		for(int[] i : ans)
			System.out.println(i[0] + " " + i[1] + " " + i[2]);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


import java.util.*;

public class C163 {

	class Line{
		public ArrayList<Integer> l = new ArrayList<Integer>();
		public int yuan;

		public Line() {
			l = new ArrayList<Integer>();
		}

	}

	class Lie{
		public int min;
		public int shu;
		public int yuan;
		public Lie(int min, int shu, int yuan) {
			super();
			this.min = min;
			this.shu = shu;
			this.yuan = yuan;
		}

	}

	class Jl{
		public int a,b,c;

		public Jl(int a, int b, int c) {
			super();
			this.a = a;
			this.b = b;
			this.c = c;
		}

		@Override
		public String toString() {
			return String.format("%d %d %d", a,b,c);
		}

	}

	Line maz[] ;
	Lie lie[];
	int juzhen[][];

	List <Jl> ans = new LinkedList<Jl>();

	void run(){

		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		maz = new Line[n+1];

		int i,j;
		for(i=0;i<n+1;i++){
			maz[i] = new Line();
			maz[i].yuan = i;
		}
		maz[0].yuan = 0;
		for(i=0;i<n-1;i++){
			int x = cin.nextInt();
			int y = cin.nextInt();
			maz[x].l.add(y);
		}

		Arrays.sort(maz,new Comparator<Line>() {

			@Override
			public int compare(Line o1, Line o2) {
				if(o1.l.size() != o2.l.size())
					return o1.l.size() - o2.l.size();
				return o1.yuan - o2.yuan;
			}

		});

		int bi[] = new int[n+1];

		for(i=0;i<=n;i++)
			bi[maz[i].yuan] = i;
		for(i=n;i>=1;i--){
			if(i != bi[i])
			{
				int w = i;
				for(j=1;j<=n;j++)
				{
					if(bi[j] == i)
						w = j;
				}
				ans.add(new Jl(1,i,w));
				int temp = bi[i];
				bi[i] = bi[w];
				bi[w] = temp;
			}
		}

		juzhen = new int[n+1][n+1];
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++)
				juzhen[i][j] = 0;
		}
		for(i=n;i>=1;i--){
			if(maz[i].l.size() == 0)
				break;
			for(j=0;j<maz[i].l.size();j++)
			{
				juzhen[i][maz[i].l.get(j)] = 1;
			}
		}

		lie = new Lie[n+1];

		lie[0] = new Lie(-9,90000,-9);

		for(j=1;j<=n;j++){

			boolean flag = false;
			int count = 0;
			int min = -1;
			for(i=1;i<=n;i++){
				if(juzhen[i][j] == 1 && flag == false)
				{
					flag =true;
					min = i;
					count ++;
				}
				else if(juzhen[i][j] == 1){
					count ++;
				}
			}
			lie[j] = new Lie(min, count,j);
		}

		Arrays.sort(lie,new Comparator<Lie>() {

			@Override
			public int compare(Lie o1, Lie o2) {

				if(o1.shu != o2.shu)
				{
					return o2.shu - o1.shu;
				}
				return o1.min - o2.min;
			}

		});

		for(i=1;i<=n;i++)
			bi[lie[i].yuan] = i;

		for(i=n;i>=1;i--){
			if(i != bi[i])
			{
				int w = i;
				for(j=1;j<=n;j++)
				{
					if(bi[j] == i)
						w = j;
				}
				ans.add(new Jl(2,i,w));
				int temp = bi[i];
				bi[i] = bi[w];
				bi[w] = temp;
			}
		}

		System.out.println(ans.size());
		for(Jl buf : ans){
			System.out.println(buf);
		}
	}

	public static void main(String[] args) {

		new C163().run();
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

    static StringTokenizer st;
    static BufferedReader in;
    static class A {
        int tip, x , y;
        public A(int tip, int x, int y) {
            this.tip = tip;
            this.x = x;
            this.y = y;
        }
    }
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int[]x = new int[n], y = new int[n];
        boolean[]used = new boolean[n+1];
        for (int i = 1; i < n; i++) {
            y[i] = nextInt();
            x[i] = nextInt();
        }
        int t = n;
        ArrayList<A> ans = new ArrayList<A>();
        for (int i = 1; i < n; i++) {
            Arrays.fill(used, false);
            for (int j = 1; j < n; j++) {
                used[x[j]] = true;
            }
            int one = 0, noneone = 0;
            for (int j = 1; j <= n; j++) {
                if (!used[j]) {
                    noneone = j;
                    break;
                }
            }
            for (int j = 1; j <= n; j++) {
                if (used[j]) {
                    one = j;
                    break;
                }
            }
            if (one==0)
                break;
            if (noneone != n) {
                ans.add(new A(2, noneone, n));
                for (int j = 1; j < t; j++) {
                    if (x[j]==n)
                        x[j] = noneone;
                }
            }
            Arrays.fill(used, false);
            for (int j = 1; j < t; j++) {
                used[y[j]] = true;
            }
            one = 0;
            for (int j = 1; j <= n; j++) {
                if (used[j]) {
                    one = j;
                    break;
                }
            }
            if (one==0)
                break;
            if (one != n) {
                ans.add(new A(1, one, n));
                for (int j = 1; j < t; j++) {
                    if (y[j]==one)
                        y[j] = n;
                }
            }
            n--;
        }
        pw.println(ans.size());
        for (A s : ans) {
            pw.println(s.tip+" "+s.x+" "+s.y);
        }
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    private static double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

    static StringTokenizer st;
    static BufferedReader in;
    static class A {
        int tip, x , y;
        public A(int tip, int x, int y) {
            this.tip = tip;
            this.x = x;
            this.y = y;
        }
    }
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int[]x = new int[n], y = new int[n];
        boolean[]used = new boolean[n+1];
        for (int i = 1; i < n; i++) {
            y[i] = nextInt();
            x[i] = nextInt();
        }
        int t = n;
        ArrayList<A> ans = new ArrayList<A>();
        for (int i = 1; i < t; i++) {
            Arrays.fill(used, false);
            for (int j = 1; j < t; j++) {
                if (x[j] <= n && y[j] <= n)
                    used[x[j]] = true;
            }
            int one = 0, noneone = 0;
            for (int j = 1; j <= n; j++) {
                if (!used[j]) {
                    noneone = j;
                    break;
                }
            }
            for (int j = 1; j <= n; j++) {
                if (used[j]) {
                    one = j;
                    break;
                }
            }
            if (one==0)
                break;
            if (noneone != n) {
                ans.add(new A(2, noneone, n));
                for (int j = 1; j < t; j++) {
                    if (x[j]==n)
                        x[j] = noneone;
                    else if (x[j]==noneone)
                        x[j] = n;
                }
            }
            Arrays.fill(used, false);
            for (int j = 1; j < t; j++) {
                if (x[j] <= n && y[j] <= n)
                    used[y[j]] = true;
            }
            one = 0;
            for (int j = 1; j <= n; j++) {
                if (used[j]) {
                    one = j;
                    break;
                }
            }
            if (one==0)
                break;
            if (one != n) {
                ans.add(new A(1, one, n));
                for (int j = 1; j < t; j++) {
                    if (y[j]==one)
                        y[j] = n;
                    else if (y[j]==n)
                        y[j] = one;
                }
            }
            n--;
        }
        pw.println(ans.size());
        for (A s : ans) {
            pw.println(s.tip+" "+s.x+" "+s.y);
        }
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    private static double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    public void swapcol(int[][] a, int c1, int c2, int n){
    	for(int i = 0; i < n; i++){
    		int tmp = a[i][c1];
    		a[i][c1] = a[i][c2];
    		a[i][c2] = tmp;
    	}
    }
    public void swaprow(int[][] a, int r1, int r2, int n){
    	for(int i = 0; i < n; i++){
    		int tmp = a[r1][i];
    		a[r1][i] = a[r2][i];
    		a[r2][i] = tmp;
    	}
    }

	public void solve() throws IOException {
		int N = nextInt();
		int[][] a = new int[N][N];
		for(int i = 0; i < N-1; i++){
			a[nextInt()-1][nextInt()-1] = 1;
		}

		int[][] swaps = new int[N*2][];
		int swap_size = 0;

		for(int c = N-1; c > 0; c--){

			for(int c2 = 0; c2 < c; c2++){
				boolean allzero = true;
				for(int r2 = 0; r2 <= c; r2++){
					if( a[r2][c2] == 1){
						allzero = false;
						break;
					}
				}
				if( allzero ){
					swaps[swap_size++] = new int[]{2, c2+1, c+1};
					swapcol(a, c2, c, N);
					break;
				}
			}

			for(int r2 = 0; r2 < c; r2++){
				boolean hasone = false;
				for(int c2 = 0; c2 <= c; c2++){
					if( a[r2][c2] == 1){
						hasone = true;
						break;
					}
				}
				if(hasone){
					swaps[swap_size++] = new int[]{1, r2+1, c+1};
					swaprow(a, r2, c, N);
					break;
				}
			}
		}

		out.println( swap_size );
		for(int i = 0; i < swap_size; i++){
			out.println( swaps[i][0] + " " + swaps[i][1] + " " + swaps[i][2] );
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new C().run();
	}

	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    public void swapcol(int[][] a, int c1, int c2, int n){
    	for(int i = 0; i < n; i++){
    		int tmp = a[i][c1];
    		a[i][c1] = a[i][c2];
    		a[i][c2] = tmp;
    	}
    }
    public void swaprow(int[][] a, int r1, int r2, int n){
    	for(int i = 0; i < n; i++){
    		int tmp = a[r1][i];
    		a[r1][i] = a[r2][i];
    		a[r2][i] = tmp;
    	}
    }

	public void solve() throws IOException {
		int N = nextInt();
		int[][] a = new int[N][N];
		for(int i = 0; i < N-1; i++){
			a[nextInt()-1][nextInt()-1] = 1;
		}

		int[][] swaps = new int[N*2][];
		int swap_size = 0;

		for(int c = N-1; c > 0; c--){

			for(int c2 = 0; c2 < c; c2++){
				boolean allzero = true;
				for(int r2 = 0; r2 < c; r2++){
					if( a[r2][c2] == 1){
						allzero = false;
						break;
					}
				}
				if( allzero ){
					swaps[swap_size++] = new int[]{2, c2+1, c+1};
					swapcol(a, c2, c, N);
					break;
				}
			}

			for(int r2 = 0; r2 < c; r2++){
				boolean hasone = false;
				for(int c2 = 0; c2 < c; c2++){
					if( a[r2][c2] == 1){
						hasone = true;
						break;
					}
				}
				if(hasone){
					swaps[swap_size++] = new int[]{1, r2+1, c+1};
					swaprow(a, r2, c, N);
					break;
				}
			}
		}

		out.println( swap_size );
		for(int i = 0; i < swap_size; i++){
			out.println( swaps[i][0] + " " + swaps[i][1] + " " + swaps[i][2] );
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new C().run();
	}

	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    public void swapcol(int[][] a, int c1, int c2, int n){
    	for(int i = 0; i < n; i++){
    		int tmp = a[i][c1];
    		a[i][c1] = a[i][c2];
    		a[i][c2] = tmp;
    	}
    }

	public void solve() throws IOException {
		int N = nextInt();
		int[][] a = new int[N][N];
		for(int i = 0; i < N-1; i++){
			a[nextInt()-1][nextInt()-1] = 1;
		}

		int[][] swaps = new int[N*2][];
		int swap_size = 0;

		for(int c = N-1; c > 0; c--){

			for(int c2 = 0; c2 < c; c2++){
				boolean allzero = true;
				for(int r2 = 0; r2 < c; r2++){
					if( a[r2][c2] == 1){
						allzero = false;
						break;
					}
				}
				if( allzero ){
					swaps[swap_size++] = new int[]{2, c2+1, c+1};
					swapcol(a, c2, c, N);
					break;
				}
			}

			for(int r2 = 0; r2 < c; r2++){
				boolean hasone = false;
				for(int c2 = 0; c2 < c; c2++){
					if( a[r2][c2] == 1){
						hasone = true;
						break;
					}
				}
				if(hasone){
					swaps[swap_size++] = new int[]{1, r2+1, c+1};
					swapcol(a, r2, c, N);
					break;
				}
			}
		}

		out.println( swap_size );
		for(int i = 0; i < swap_size; i++){
			out.println( swaps[i][0] + " " + swaps[i][1] + " " + swaps[i][2] );
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new C().run();
	}

	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    public void swapcol(int[][] a, int c1, int c2, int n){
    	for(int i = 0; i < n; i++){
    		int tmp = a[i][c1];
    		a[i][c1] = a[i][c2];
    		a[i][c2] = tmp;
    	}
    }

	public void solve() throws IOException {
		int N = nextInt();
		int[][] a = new int[N][N];
		for(int i = 0; i < N-1; i++){
			a[nextInt()-1][nextInt()-1] = 1;
		}
		out.println( (N-1)*2 );
		for(int c = N-1; c > 0; c--){

			for(int c2 = 0; c2 <= c; c2++){
				boolean allzero = true;
				for(int r2 = 0; r2 < N; r2++){
					if( a[r2][c2] == 1){
						allzero = false;
						break;
					}
				}
				if( allzero ){
					out.println(2 + " " + (c2+1) + " " + (c+1) );
					swapcol(a, c2, c, N);
					break;
				}
			}

			for(int r2 = 0; r2 <= c; r2++){
				boolean hasone = false;
				for(int c2 = 0; c2 <= c; c2++){
					if( a[r2][c2] == 1){
						hasone = true;
						break;
					}
				}
				if(hasone){
					out.println(1 + " " + (r2+1) + " " + (c+1) );
					swapcol(a, r2, c, N);
					break;
				}
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new C().run();
	}

	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.util.Scanner;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	class C {
		int a, b;

		C(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public void solve(int testNumber, Scanner in, PrintWriter out) {
		int n = in.nextInt();
		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n - 1; ++i) {
			g[in.nextInt() - 1][in.nextInt() - 1] = true;
		}
		int[] maxColumnIndexOfRow = new int[n];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					maxColumnIndexOfRow[i] = j;
		List<C> list = new ArrayList<C>();
		for (int i = 0; i < n; ++i) list.add(new C(i, maxColumnIndexOfRow[i]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curRow = new int[n];
		for (int i = 0; i < n; ++i) curRow[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nRow = list.get(i).a;
			int oRow = find(i, curRow);
			swapRow(nRow, oRow, g);
			swap(nRow, oRow, curRow);
			out.println(String.format("1 %d %d", nRow + 1, oRow + 1));
		}

		int[] minRowIndexOfColumn = new int[n];
		Arrays.fill(minRowIndexOfColumn, 10000);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					minRowIndexOfColumn[j] = Math.min(minRowIndexOfColumn[j], i);
		list = new ArrayList<C>();
		for (int j = 0; j < n; ++j) list.add(new C(j, minRowIndexOfColumn[j]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curColumn = new int[n];
		for (int i = 0; i < n; ++i) curColumn[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nCol = list.get(i).a;
			int oCol = find(i, curColumn);
			swap(nCol, oCol, curColumn);
			out.println(String.format("2 %d %d", nCol + 1, oCol + 1));
		}
	}

	private void swap(int nRow, int oRow, int[] curRow) {
		int t = curRow[oRow];
		curRow[oRow] = curRow[nRow];
		curRow[nRow] = t;
	}

	private void swapRow(int nRow, int oRow, boolean[][] g) {
		boolean[] t = new boolean[g.length];
		for (int i = 0; i < g.length; ++i) t[i] = g[oRow][i];
		for (int i = 0; i < g.length; ++i) g[oRow][i] = g[nRow][i];
		for (int i = 0; i < g.length; ++i) g[nRow][i] = t[i];
	}

	private int find(int n, int[] a) {
		for (int i = 0; i < a.length; ++i) if (a[i] == n) return i;
		return -1;
	}
}


import java.util.Scanner;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	class C {
		int a, b;

		C(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public void solve(int testNumber, Scanner in, PrintWriter out) {
		int n = in.nextInt();
		List<String> res = new ArrayList<String>();
		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n - 1; ++i) {
			g[in.nextInt() - 1][in.nextInt() - 1] = true;
		}
		int[] maxColumnIndexOfRow = new int[n];
		Arrays.fill(maxColumnIndexOfRow, -1);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					maxColumnIndexOfRow[i] = j;
		List<C> list = new ArrayList<C>();
		for (int i = 0; i < n; ++i) list.add(new C(i, maxColumnIndexOfRow[i]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curRow = new int[n];
		for (int i = 0; i < n; ++i) curRow[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nRow = list.get(i).a;
			int oRow = find(nRow, curRow);
			swapRow(nRow, oRow, g);
			swap(nRow, oRow, curRow);
			if (nRow == oRow) continue;
			res.add(String.format("1 %d %d", nRow + 1, oRow + 1));
		}

		int[] minRowIndexOfColumn = new int[n];
		Arrays.fill(minRowIndexOfColumn, 10000);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					minRowIndexOfColumn[j] = Math.min(minRowIndexOfColumn[j], i);
		list = new ArrayList<C>();
		for (int j = 0; j < n; ++j) list.add(new C(j, minRowIndexOfColumn[j]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curColumn = new int[n];
		for (int i = 0; i < n; ++i) curColumn[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nCol = list.get(i).a;
			int oCol = find(nCol, curColumn);
			swap(nCol, oCol, curColumn);
			if (nCol == oCol) continue;
			res.add(String.format("2 %d %d", nCol + 1, oCol + 1));
		}
		out.println(res.size());
		if (res.size() > 0) {
			for (int i = 0; i < res.size(); ++i)
				out.println(res.get(i));
		}
	}

	private void swap(int nRow, int oRow, int[] curRow) {
		int t = curRow[oRow];
		curRow[oRow] = curRow[nRow];
		curRow[nRow] = t;
	}

	private void swapRow(int nRow, int oRow, boolean[][] g) {
		boolean[] t = new boolean[g.length];
		for (int i = 0; i < g.length; ++i) t[i] = g[oRow][i];
		for (int i = 0; i < g.length; ++i) g[oRow][i] = g[nRow][i];
		for (int i = 0; i < g.length; ++i) g[nRow][i] = t[i];
	}

	private int find(int n, int[] a) {
		for (int i = 0; i < a.length; ++i) if (a[i] == n) return i;
		return -1;
	}
}


import java.util.Scanner;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	class C {
		int a, b;

		C(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public void solve(int testNumber, Scanner in, PrintWriter out) {
		int n = in.nextInt();
		boolean printed = false;
		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n - 1; ++i) {
			g[in.nextInt() - 1][in.nextInt() - 1] = true;
		}
		int[] maxColumnIndexOfRow = new int[n];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					maxColumnIndexOfRow[i] = j;
		List<C> list = new ArrayList<C>();
		for (int i = 0; i < n; ++i) list.add(new C(i, maxColumnIndexOfRow[i]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curRow = new int[n];
		for (int i = 0; i < n; ++i) curRow[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nRow = list.get(i).a;
			int oRow = find(i, curRow);
			swapRow(nRow, oRow, g);
			swap(nRow, oRow, curRow);
			if (nRow == oRow) continue;
			out.println(String.format("1 %d %d", nRow + 1, oRow + 1));
			printed = true;
		}

		int[] minRowIndexOfColumn = new int[n];
		Arrays.fill(minRowIndexOfColumn, 10000);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					minRowIndexOfColumn[j] = Math.min(minRowIndexOfColumn[j], i);
		list = new ArrayList<C>();
		for (int j = 0; j < n; ++j) list.add(new C(j, minRowIndexOfColumn[j]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curColumn = new int[n];
		for (int i = 0; i < n; ++i) curColumn[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nCol = list.get(i).a;
			int oCol = find(i, curColumn);
			swap(nCol, oCol, curColumn);
			if (nCol == oCol) continue;
			out.println(String.format("2 %d %d", nCol + 1, oCol + 1));
			printed = true;
		}
		if (!printed) {
			out.print(0);
		}
	}

	private void swap(int nRow, int oRow, int[] curRow) {
		int t = curRow[oRow];
		curRow[oRow] = curRow[nRow];
		curRow[nRow] = t;
	}

	private void swapRow(int nRow, int oRow, boolean[][] g) {
		boolean[] t = new boolean[g.length];
		for (int i = 0; i < g.length; ++i) t[i] = g[oRow][i];
		for (int i = 0; i < g.length; ++i) g[oRow][i] = g[nRow][i];
		for (int i = 0; i < g.length; ++i) g[nRow][i] = t[i];
	}

	private int find(int n, int[] a) {
		for (int i = 0; i < a.length; ++i) if (a[i] == n) return i;
		return -1;
	}
}


import java.util.Scanner;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	class C {
		int a, b;

		C(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public void solve(int testNumber, Scanner in, PrintWriter out) {
		int n = in.nextInt();
		List<String> res = new ArrayList<String>();
		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n - 1; ++i) {
			g[in.nextInt() - 1][in.nextInt() - 1] = true;
		}
		int[] maxColumnIndexOfRow = new int[n];
		Arrays.fill(maxColumnIndexOfRow, -1);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					maxColumnIndexOfRow[i] = j;
		List<C> list = new ArrayList<C>();
		for (int i = 0; i < n; ++i) list.add(new C(i, maxColumnIndexOfRow[i]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curRow = new int[n];
		for (int i = 0; i < n; ++i) curRow[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nRow = list.get(i).a;
			int nRowIndex = find(nRow, curRow);
			swapRow(i, nRowIndex, g);
			swap(i, nRowIndex, curRow);
			if (i == nRowIndex) continue;
			res.add(String.format("1 %d %d", i + 1, nRowIndex + 1));
		}

		int[] minRowIndexOfColumn = new int[n];
		Arrays.fill(minRowIndexOfColumn, 10000);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					minRowIndexOfColumn[j] = Math.min(minRowIndexOfColumn[j], i);
		list = new ArrayList<C>();
		for (int j = 0; j < n; ++j) list.add(new C(j, minRowIndexOfColumn[j]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curColumn = new int[n];
		for (int i = 0; i < n; ++i) curColumn[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nCol = list.get(i).a;
			int nColIndex = find(nCol, curColumn);
			swap(i, nColIndex, curColumn);
			if (i == nColIndex) continue;
			res.add(String.format("2 %d %d", i + 1, nColIndex + 1));
		}
		out.println(res.size());
		if (res.size() > 0) {
			for (int i = 0; i < res.size(); ++i)
				out.println(res.get(i));
		}
	}

	private void swap(int nRow, int oRow, int[] curRow) {
		int t = curRow[oRow];
		curRow[oRow] = curRow[nRow];
		curRow[nRow] = t;
	}

	private void swapRow(int nRow, int oRow, boolean[][] g) {
		boolean[] t = new boolean[g.length];
		for (int i = 0; i < g.length; ++i) t[i] = g[oRow][i];
		for (int i = 0; i < g.length; ++i) g[oRow][i] = g[nRow][i];
		for (int i = 0; i < g.length; ++i) g[nRow][i] = t[i];
	}

	private int find(int n, int[] a) {
		for (int i = 0; i < a.length; ++i) if (a[i] == n) return i;
		return -1;
	}
}


import java.util.Scanner;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	class C {
		int a, b;

		C(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public void solve(int testNumber, Scanner in, PrintWriter out) {
		int n = in.nextInt();
		List<String> res = new ArrayList<String>();
		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n - 1; ++i) {
			g[in.nextInt() - 1][in.nextInt() - 1] = true;
		}
		int[] maxColumnIndexOfRow = new int[n];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					maxColumnIndexOfRow[i] = j;
		List<C> list = new ArrayList<C>();
		for (int i = 0; i < n; ++i) list.add(new C(i, maxColumnIndexOfRow[i]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curRow = new int[n];
		for (int i = 0; i < n; ++i) curRow[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nRow = list.get(i).a;
			int oRow = find(i, curRow);
			swapRow(nRow, oRow, g);
			swap(nRow, oRow, curRow);
			if (nRow == oRow) continue;
			res.add(String.format("1 %d %d", nRow + 1, oRow + 1));
		}

		int[] minRowIndexOfColumn = new int[n];
		Arrays.fill(minRowIndexOfColumn, 10000);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				if (g[i][j])
					minRowIndexOfColumn[j] = Math.min(minRowIndexOfColumn[j], i);
		list = new ArrayList<C>();
		for (int j = 0; j < n; ++j) list.add(new C(j, minRowIndexOfColumn[j]));
		Collections.sort(list, new Comparator<C>() {
			public int compare(C o1, C o2) {
				return o1.b - o2.b;
			}
		});
		int[] curColumn = new int[n];
		for (int i = 0; i < n; ++i) curColumn[i] = i;
		for (int i = 0; i < list.size(); ++i) {
			int nCol = list.get(i).a;
			int oCol = find(i, curColumn);
			swap(nCol, oCol, curColumn);
			if (nCol == oCol) continue;
			res.add(String.format("2 %d %d", nCol + 1, oCol + 1));
		}
		out.println(res.size());
		if (res.size() > 0) {
			for (int i = 0; i < res.size(); ++i)
				out.println(res.get(i));
		}
	}

	private void swap(int nRow, int oRow, int[] curRow) {
		int t = curRow[oRow];
		curRow[oRow] = curRow[nRow];
		curRow[nRow] = t;
	}

	private void swapRow(int nRow, int oRow, boolean[][] g) {
		boolean[] t = new boolean[g.length];
		for (int i = 0; i < g.length; ++i) t[i] = g[oRow][i];
		for (int i = 0; i < g.length; ++i) g[oRow][i] = g[nRow][i];
		for (int i = 0; i < g.length; ++i) g[nRow][i] = t[i];
	}

	private int find(int n, int[] a) {
		for (int i = 0; i < a.length; ++i) if (a[i] == n) return i;
		return -1;
	}
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int count = in.readInt();
        int[] row = new int[count - 1];
        int[] column = new int[count - 1];
        IOUtils.readIntArrays(in, row, column);
        MiscUtils.decreaseByOne(row, column);
        int[] queue = new int[count - 1];
        int size = 0;
        int nextRow = count - 1;
        int nextColumn = 0;
        List<Swap> answer = new ArrayList<Swap>();
        boolean[] added = new boolean[count - 1];
        for (int i = 0; i < count - 1; i++) {
            if (size == i) {
                for (int j = 0; j < count - 1; j++) {
                    if (!added[j]) {
                        added[j] = true;
                        queue[size++] = j;
                        break;
                    }
                }
            }
            int currentRow = row[queue[i]];
            int currentColumn = column[queue[i]];
            if (currentRow <= nextRow) {
                if (currentRow != nextRow)
                    answer.add(new Swap(1, currentRow + 1, nextRow + 1));
                for (int j = 0; j < count - 1; j++) {
                    if (currentRow == row[j]) {
                        row[j] = nextRow;
                        if (!added[j]) {
                            queue[size++] = j;
                            added[j] = true;
                        }
                    } else if (nextRow == row[j])
                        row[j] = currentRow;
                }
                nextRow--;
            }
            if (currentColumn >= nextColumn) {
                if (currentColumn != nextColumn)
                    answer.add(new Swap(2, currentColumn + 1, nextColumn + 1));
                for (int j = 0; j < count - 1; j++) {
                    if (currentColumn == column[j]) {
                        column[j] = nextColumn;
                        if (!added[j]) {
                            queue[size++] = j;
                            added[j] = true;
                        }
                    } else if (nextColumn == column[j])
                        column[j] = currentColumn;
                }
                nextColumn++;
            }
        }
        for (int i = 0, j = nextColumn - 1; i < j; i++, j--)
            answer.add(new Swap(2, i + 1, j + 1));
        out.printLine(answer.size());
        for (Swap swap : answer)
            out.printLine(swap.type, swap.from, swap.to);
    }

    static class Swap {
        final int type, from, to;

        Swap(int type, int from, int to) {
            this.type = type;
            this.from = from;
            this.to = to;
        }
    }
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

    public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static void readIntArrays(InputReader in, int[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readInt();
		}
	}

	}

class MiscUtils {

    public static void decreaseByOne(int[]...arrays) {
		for (int[] array : arrays) {
			for (int i = 0; i < array.length; i++)
				array[i]--;
		}
	}

	}