import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                            //(new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;
        //PrintWriter pw = new PrintWriter("output.out", "UTF-8");

        int n = parseInt(in.readLine());
        point [] one = new point[n-1];

        for(int i=0; i<one.length; i++) {
            tk = new StringTokenizer(in.readLine());
            one[i] = new point(parseInt(tk.nextToken()),parseInt(tk.nextToken()));
        }

        int cnt = 0;

        while(n > 1) {
            int [] col = new int[n+1];
            for(int i=0; i<one.length; i++)
                if(one[i].r<=n && one[i].c<=n)
                    col[one[i].c]++;

            int e = 0;
            for(int i=1; i<=n; i++)
                if(col[i]==0) {
                    e = i;
                    break;
                }

            if(e!=n) {
                for(int i=0; i<one.length; i++)
                    if(one[i].c==n)
                        one[i].c = e;
                    else if(one[i].c==e)
                        one[i].c = n;

                out.append("2 ").append(e).append(" ").append(n).append("\n");
                cnt++;
            }

            int [] row = new int[n+1];
            for(int i=0; i<one.length; i++)
                if(one[i].c<=n && one[i].r<=n)
                    row[one[i].r]++;

            e = 0;
            for(int i=1; i<=n; i++)
                if(row[i]>0) {
                    e = i;
                    break;
                }

            if(e!=n) {
                for(int i=0; i<one.length; i++)
                    if(one[i].r==e)
                        one[i].r = n;
                    else if(one[i].r==n)
                        one[i].r = e;

                out.append("1 ").append(e).append(" ").append(n).append("\n");
                cnt++;
            }

            n--;
        }

        System.out.println(cnt);
        System.out.print(out);
    }

}

class point {
    int r,c;

    public point(int r,int c) {
        this.r = r;
        this.c = c;
    }
}


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

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

		int n = in.nextInt(), x, y, numActions = 0, numOnes = n - 1, colIdx, rowIdx;
		String ans = "";
		int[][] matrix = new int[n + 1][n + 1];
		for (int i = 0; i < n - 1; i++) {
			x = in.nextInt();
			y = in.nextInt();
			matrix[x][y] = 1;
		}

		// Use constructive algorithm to solve
		while (n > 1) {
			// Find column with NO 1s
			colIdx = colNo1s(matrix, n);
			if (colIdx != -1) {
				swapCols(matrix, colIdx, n);
				numActions++;
				ans = ans + 2 + " " + colIdx + " " + n + "\n";
			}
			// Find row with at least one 1
			rowIdx = rowAtLeastOne1(matrix, n);
			if (rowIdx != -1) {
				swapRows(matrix, rowIdx, n);
				numActions++;
				ans = ans + 1 + " " + rowIdx + " " + n + "\n";
			}
			n--;
		}

		out.println(numActions);
		out.print(ans);

		out.close();
	}

	public static int colNo1s(int[][] matrix, int n) {
		boolean flag;
		for (int col = 1; col < n; col++) {
			flag = true;
			for (int row = 1; row <= n; row++) {
				if (matrix[row][col] == 1) {
					flag = false;
					break;
				}
			}
			if (flag == true) {
				return col;
			}
		}
		return -1;
	}

	public static void swapCols(int[][] matrix, int colIdx, int n) {
		int temp;
		for (int row = 1; row < matrix.length; row++) {
			temp = matrix[row][colIdx];
			matrix[row][colIdx] = matrix[row][n];
			matrix[row][n] = temp;
		}
	}

	public static int rowAtLeastOne1(int[][] matrix, int n) {
		for (int row = 1; row < n; row++) {
			for (int col = 1; col <= n; col++) {
				if (matrix[row][col] == 1) {
					return row;
				}
			}
		}
		return -1;
	}

	public static void swapRows(int[][] matrix, int rowIdx, int n) {
		int temp;
		for (int col = 1; col < matrix.length; col++) {
			temp = matrix[rowIdx][col];
			matrix[rowIdx][col] = matrix[n][col];
			matrix[n][col] = temp;
		}
	}

	static class InputReader {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

	}
}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String pr = "";
        int len = sc.nextInt();
        int[][] arr = new int[len][len];

        for (int i = 0; i < len-1; i++) {
         arr[sc.nextInt()-1][sc.nextInt()-1] = 1;
        }

        int time = 0;
        while (len-- != 1) {

            int count = 0;
            int i = 0;

            // find col
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[j][i];
                }

                if (count == 0) {
                    break;
                }
                count = 0;
            }

            // swap
            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[k][i];
                arr[k][i] = arr[k][len];
                arr[k][len] = temp;

            }
            pr+="2 "+(i+1)+" "+(len+1)+"\n";
            time++;
            }

            // find row
            count = 0;
            i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[i][j];
                }

                if (count >= 1) {
                    break;
                }
                count = 0;
            }

            //swap
            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[len][k];
                arr[len][k] = arr[i][k];
                arr[i][k] = temp;

            }

            pr+="1 "+(i+1)+" "+(len+1)+"\n";
            time++;

            }

    }// while

        System.out.println(time);
            System.out.printf(pr.trim());

}

    private static boolean isOK(int[][] arr) {

           int c = 0;
            for (int k = 0; k < arr.length ; k++)
            for (int l = k; l < arr[0].length; l++)
                c+=arr[k][l];
            if(c==0)
                return true;

            return false;

    }

}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class ColorfulRabbits {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String pr = "";
        int len = sc.nextInt();
        int[][] arr = new int[len][len];

        for (int i = 0; i < len-1; i++) {
         arr[sc.nextInt()-1][sc.nextInt()-1] = 1;
        }

        int time = 0;
        while (len-- != 1) {

            int c = 0;
            for (int k = 0; k < arr.length ; k++)
            for (int l = k; l < arr[0].length; l++)
                c+=arr[k][l];
            if(c==0)
                break;

            int count = 0;
            int i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[j][i];
                }

                if (count == 0) {
                    break;
                }
                count = 0;
            }

            for (int k = 0; k <= len; k++) {
                int temp = arr[k][i];
                arr[k][i] = arr[k][len];
                arr[k][len] = temp;

            }
            pr+="2 "+(i+1)+" "+(len+1)+"\n";

            c = 0;
            for (int k = 0; k < arr.length ; k++)
            for (int l = k; l < arr[0].length; l++)
                c+=arr[k][l];
            if(c==0)
                break;

            time++;
            count = 0;
            i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[i][j];
                }

                if (count == 1) {
                    break;
                }
                count = 0;
            }

            for (int k = 0; k <= len; k++) {
                int temp = arr[len][k];
                arr[len][k] = arr[i][k];
                arr[i][k] = temp;

            }

            pr+="1 "+(i+1)+" "+(len+1)+"\n";
            time++;

    }// while

        System.out.println(time);
            System.out.printf(pr);

}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static int[][] matrix;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt()+1;
        matrix = new int[n][n];
        for(int i = 1; i<=n-2; i++){
            matrix[in.nextInt()][in.nextInt()] = 1;
        }
        if(checkMatrix()){
            System.out.println("0");
            return;
        }

        ArrayList<String> op1 = new ArrayList();
        ArrayList<String> op2 = new ArrayList();
        while(n != 1){
            for(int c = 1 ; c< n-1; c++){
                boolean emtyCol = true;
                for(int r = 1; r<n; r++){
                    if(matrix[r][c] == 1){
                       //System.out.println("Emty col: "+c+" ");
                       emtyCol =  false;
                       break;
                    }
                }
                if(emtyCol){
                   //System.out.println("Emty col: "+c+" ");
                   swapCol(c, n-1);
                   op2.add("2 "+c+" "+(n-1));
                   break;
                }
            }
            //print();
            boolean LastrowWith1 = false;
            for(int c = 1; c< n; c++){
                if(matrix[n-1][c] == 1){
                    LastrowWith1 = true;
                    break;
                }
            }
            if(!LastrowWith1){
                for(int r = 1 ; r<n-1; r++){
                    for(int c = 1; c<n; c++){
                        if(matrix[r][c] == 1){
                           LastrowWith1 = true;
                           break;
                        }
                    }
                    if(LastrowWith1){
                        //System.out.println("Emty row: "+r+" ");
                        swapRow(r, n-1);
                        op1.add("1 "+r+" "+(n-1));
                        //print();
                        break;
                    }
                }
            }

            n = n-1;
        }
        System.out.println(op1.size()+op2.size());
        for(int i = 0; i<op1.size(); i++)
            System.out.println(op1.get(i));
        for(int i = 0; i<op2.size(); i++)
            System.out.println(op2.get(i));

    }

    public static void swapRow(int r1, int r2){
        int[] temp = matrix[r1];
        matrix[r1] = matrix[r2];
        matrix[r2] = temp;
    }
    public static void swapCol(int c1, int c2){
        for(int r = 1; r<matrix.length; r++){
            matrix[r][c1] = matrix[r][c2];
            matrix[r][c2] = 0;
        }
    }
    public static void print(){
        for(int i = 1; i<matrix.length; i++){
            for(int j = 1; j<matrix.length; j++){
                System.out.print(matrix[i][j]+"");

            }
            System.out.println("");
        }
        System.out.println("");
    }

    public static boolean checkMatrix(){
        int count = 0;
        for(int i = 1; i<matrix.length; i++){
            for(int j = 1; j<i; j++){
                if(matrix[i][j] == 1)
                    count++;
            }
        }
        return (count == (matrix.length-2) );

    }
}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String pr = "";
        int len = sc.nextInt();
        int[][] arr = new int[len][len];

        for (int i = 0; i < len-1; i++) {
         arr[sc.nextInt()-1][sc.nextInt()-1] = 1;
        }

        int time = 0;
        while (len-- != 1) {

            if(isOK(arr))
                break;

            int count = 0;
            int i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[j][i];
                }

                if (count == 0) {
                    break;
                }
                count = 0;
            }

            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[k][i];
                arr[k][i] = arr[k][len];
                arr[k][len] = temp;

            }
            pr+="2 "+(i+1)+" "+(len+1)+"\n";
            time++;
            }

           if(isOK(arr))
                break;

            count = 0;
            i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[i][j];
                }

                if (count == 1) {
                    break;
                }
                count = 0;
            }

            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[len][k];
                arr[len][k] = arr[i][k];
                arr[i][k] = temp;

            }

            pr+="1 "+(i+1)+" "+(len+1)+"\n";
            time++;

            }

        for (int k = 0; k < arr.length ; k++) {
            for (int l = 0; l < arr[i].length; l++) {
                System.out.print(arr[k][l]);
            }

            System.out.println();

        }
        System.out.println();

    }// while

        System.out.println(time);
            System.out.printf(pr.trim());

}

    private static boolean isOK(int[][] arr) {

           int c = 0;
            for (int k = 0; k < arr.length ; k++)
            for (int l = k; l < arr[0].length; l++)
                c+=arr[k][l];
            if(c==0)
                return true;

            return false;

    }

}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String pr = "";
        int len = sc.nextInt();
        int[][] arr = new int[len][len];

        for (int i = 0; i < len-1; i++) {
         arr[sc.nextInt()-1][sc.nextInt()-1] = 1;
        }

        int time = 0;
        while (len-- != 1) {

            if(isOK(arr))
                break;

            int count = 0;
            int i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[j][i];
                }

                if (count == 0) {
                    break;
                }
                count = 0;
            }

            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[k][i];
                arr[k][i] = arr[k][len];
                arr[k][len] = temp;

            }
            pr+="2 "+(i+1)+" "+(len+1)+"\n";
            time++;
            }

           if(isOK(arr))
                break;

            count = 0;
            i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[i][j];
                }

                if (count == 1) {
                    break;
                }
                count = 0;
            }

            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[len][k];
                arr[len][k] = arr[i][k];
                arr[i][k] = temp;

            }

            pr+="1 "+(i+1)+" "+(len+1)+"\n";
            time++;

            }

    }// while

        System.out.println(time);
            System.out.printf(pr.trim());

}

    private static boolean isOK(int[][] arr) {

           int c = 0;
            for (int k = 0; k < arr.length ; k++)
            for (int l = k; l < arr[0].length; l++)
                c+=arr[k][l];
            if(c==0)
                return true;

            return false;

    }

}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String pr = "";
        int len = sc.nextInt();
        int[][] arr = new int[len][len];

        for (int i = 0; i < len-1; i++) {
         arr[sc.nextInt()-1][sc.nextInt()-1] = 1;
        }

        int time = 0;
        while (len-- != 1) {

              if(isOK(arr))
                  break;
            int count = 0;
            int i = 0;

            // find col
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[j][i];
                }

                if (count == 0) {
                    break;
                }
                count = 0;
            }

            // swap
            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[k][i];
                arr[k][i] = arr[k][len];
                arr[k][len] = temp;

            }
            pr+="2 "+(i+1)+" "+(len+1)+"\n";
            time++;
            }

              if(isOK(arr))
                  break;

            // find row
            count = 0;
            i = 0;
            for (; i <= len; i++) {
                for (int j = 0; j <= len; j++) {
                    count += arr[i][j];
                }

                if (count >= 1) {
                    break;
                }
                count = 0;
            }

            //swap
            if(len!=i){
            for (int k = 0; k <= len; k++) {
                int temp = arr[len][k];
                arr[len][k] = arr[i][k];
                arr[i][k] = temp;

            }

            pr+="1 "+(i+1)+" "+(len+1)+"\n";
            time++;

            }

    }// while

        System.out.println(time);
            System.out.printf(pr.trim());

}

    private static boolean isOK(int[][] arr) {

           int c = 0;
            for (int k = 0; k < arr.length ; k++)
            for (int l = k; l < arr[0].length; l++)
                c+=arr[k][l];
            if(c==0)
                return true;

            return false;

    }

}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF266C extends PrintWriter {
	CF266C() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF266C o = new CF266C(); o.main(); o.flush();
	}

	int[] tt, ii, jj;
	int cnt;
	void solve(byte[][] aa, int n) {
		int[] pp = new int[n];
		int[] zz = new int[n];
		for (int i = 0; i < n; i++) {
			pp[i] = i;
			int j = n - 1;
			while (j >= 0 && aa[i][j] == 0)
				j--;
			zz[i] = j;
		}
		for (int i1 = 0; i1 < n; i1++) {
			int i2 = i1, tmp;
			for (int i = i1 + 1; i < n; i++)
				if (zz[i2] > zz[i])
					i2 = i;
			if (i2 != i1) {
				tt[cnt] = 1; ii[cnt] = i1; jj[cnt] = i2; cnt++;
				tmp = pp[i1]; pp[i1] = pp[i2]; pp[i2] = tmp;
				tmp = zz[i1]; zz[i1] = zz[i2]; zz[i2] = tmp;
			}
		}
		byte[][] bb = new byte[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				bb[i][j] = aa[pp[i]][j];
		for (int j = 0; j < n; j++) {
			pp[j] = j;
			int i = 0;
			while (i < n && bb[i][j] == 0)
				i++;
			zz[j] = i;
		}
		for (int j1 = 0; j1 < n; j1++) {
			int j2 = j1, tmp;
			for (int j = j1 + 1; j < n; j++)
				if (zz[j2] > zz[j])
					j2 = j;
			if (j2 != j1) {
				tt[cnt] = 2; ii[cnt] = j1; jj[cnt] = j2; cnt++;
				tmp = pp[j1]; pp[j1] = pp[j2]; pp[j2] = tmp;
				tmp = zz[j1]; zz[j1] = zz[j2]; zz[j2] = tmp;
			}
		}
	}
	void main() {
		int n = sc.nextInt();
		byte[][] aa = new byte[n][n];
		for (int h = 0; h < n - 1; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i][j] = 1;
		}
		tt = new int[n * 2];
		ii = new int[n * 2];
		jj = new int[n * 2];
		solve(aa, n);
		println(cnt);
		for (int h = 0; h < cnt; h++)
			println(tt[h] + " " + (ii[h] + 1) + " " + (jj[h] + 1));
	}
}


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

public class Main {

    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int[][] matrix = new int[n][n];

        for (int i = 0; i < n - 1; i++) {
            matrix[in.nextInt() - 1][in.nextInt() - 1] = 1;
        }

        int c = 0;
        String s = "";
        loop:
        for (int i = n - 1; i > -1; i--) {

            int Col = colChecker(matrix, i);
            if (Col != -1 && i != Col) {
                s += ("2 " + (i + 1) + " " + (Col + 1)) + "\n";
                changeCol(matrix, i, Col);
                c++;
            }

            int Row = rowChecker(matrix, i);
            if (Row != -1 && i != Row) {
                s += ("1 " + (i + 1) + " " + (Row + 1)) + "\n";
                changeRow(matrix, i, Row);
                c++;
            }
        }
        System.out.println(c);
        System.out.print(s);

    }

    public static void changeRow(int[][] matrix, int i, int index) {
        int[] t = matrix[i];
        matrix[i] = matrix[index];
        matrix[index] = t;
    }

    public static void changeCol(int[][] matrix, int j, int index) {
        for (int k = 0; k < matrix.length; k++) {
            int t = matrix[k][j];
            matrix[k][j] = matrix[k][index];
            matrix[k][index] = t;
        }
    }

    public static int colChecker(int[][] matrix, int L) {
        for (int i = 0; i <= L; i++) {
            boolean check = true;
            for (int j = 0; j <= L; j++) {
                if (matrix[j][i] == 1) {
                    check = false;
                    break;
                }
            }
            if (check) {
                return i;
            }
        }
        return -1;
    }

    public static int rowChecker(int[][] matrix, int L) {
        for (int i = 0; i <= L; i++) {
            for (int j = 0; j <= L; j++) {
                if (matrix[i][j] == 1) {
                    return i;
                }
            }
        }
        return -1;
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Diagnol266C {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	int mod = (int)(Math.pow(10,9)+7);

	void solve() {
		int n = ni();
		int a[][] = new int[n][n];
		int col[] = new int[n];
		int row[] = new int[n];

		for(int i = 0 ; i<n-1 ; i++) {
			int j = ni()-1;
			int k = ni()-1;
			a[j][k] = 1;
			col[k]++;

			row[j]++;

		}

		int c = 0;

		while(n!=1) {
			int c0 = -1;
			for(int i = 0 ; i<n ; i++) {
				if(col[i] == 0) {
					c0 = i;
					break;
				}
			}
			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(2+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[i][n-1];
					a[i][n-1] = a[i][c0];
					a[i][c0] = y;
				}
				y = col[n-1];
				col[n-1] = col[c0];
				col[c0] = y;

			}
			//display2D(a);
			c0 = -1;
			for(int i = n-2 ; i>=0 ; i-- ) {
				if(row[i] != 0) {
					c0 = i;
					break;
				}
			}

			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(1+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[n-1][i];
					a[n-1][i] = a[c0][i];
					a[c0][i] = y;
				}
				row[c0] = 0;
				for(int i = c0 ; i<n ; i++) if(a[c0][i] == 1) row[c0]++;
			}
			for(int i = 0 ; i<n-1 ; i++) if(a[n-1][i] == 1) col[i]--;
			/*for(int i : col) System.out.print(i);
			System.out.println();*/
			n--;
			//display2D(a);
		}
		System.out.println(c);

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
		//tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

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

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Diagnol266C {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	int mod = (int)(Math.pow(10,9)+7);

	void solve() {
		int n = ni();
		int a[][] = new int[n][n];
		int col[] = new int[n];
		int row[] = new int[n];

		for(int i = 0 ; i<n-1 ; i++) {
			int j = ni()-1;
			int k = ni()-1;
			a[j][k] = 1;
			col[k]++;

			row[j]++;

		}

		int c = 0;

		while(n!=1) {
			int c0 = -1;
			for(int i = 0 ; i<n ; i++) {
				if(col[i] == 0) {
					c0 = i;
					break;
				}
			}
			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(2+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[i][n-1];
					a[i][n-1] = a[i][c0];
					a[i][c0] = y;
				}
				y = col[n-1];
				col[n-1] = col[c0];
				col[c0] = y;

			}
			//display2D(a);
			c0 = -1;
			for(int i = n-1 ; i>=0 ; i-- ) {
				if(row[i] != 0) {
					c0 = i;
					break;
				}
			}

			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(1+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[n-1][i];
					a[n-1][i] = a[c0][i];
					a[c0][i] = y;
				}
				row[c0] = 0;
				for(int i = c0 ; i<n ; i++) if(a[c0][i] == 1) row[c0]++;
			}
			for(int i = 0 ; i<n-1 ; i++) if(a[n-1][i] == 1) col[i]--;
			/*for(int i : col) System.out.print(i);
			System.out.println();*/
			n--;
			//display2D(a);
		}
		System.out.println(c);

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
		//tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

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

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Diagnol266C {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	int mod = (int)(Math.pow(10,9)+7);

	void solve() {
		int n = ni();
		int a[][] = new int[n][n];
		int col[] = new int[n];
		int row[] = new int[n];

		for(int i = 0 ; i<n-1 ; i++) {
			int j = ni()-1;
			int k = ni()-1;
			a[j][k] = 1;
			col[k]++;
			if(j<=k) {

				row[j]++;
			}
		}

		int c = 0;

		while(n!=1) {
			int c0 = -1;
			for(int i = 0 ; i<n ; i++) {
				if(col[i] == 0) {
					c0 = i;
					break;
				}
			}
			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(2+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[i][n-1];
					a[i][n-1] = a[i][c0];
					a[i][c0] = y;
				}
				y = col[n-1];
				col[n-1] = col[c0];
				col[c0] = y;

			}
			//display2D(a);
			c0 = -1;
			for(int i = n-1 ; i>=0 ; i-- ) {
				if(row[i] != 0) {
					c0 = i;
					break;
				}
			}

			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(1+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[n-1][i];
					a[n-1][i] = a[c0][i];
					a[c0][i] = y;
				}
				row[c0] = 0;
				for(int i = c0 ; i<n ; i++) if(a[c0][i] == 1) row[c0]++;
			}
			/*for(int i : col) System.out.print(i);
			System.out.println();*/
			n--;
			//display2D(a);
		}
		System.out.println(c);

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
		//tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

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

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Diagnol266C {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	int mod = (int)(Math.pow(10,9)+7);

	void solve() {
		int n = ni();
		StringBuilder st = new StringBuilder();
		int a[][] = new int[n][n];
		int col[] = new int[n];
		int row[] = new int[n];

		for(int i = 0 ; i<n-1 ; i++) {
			int j = ni()-1;
			int k = ni()-1;
			a[j][k] = 1;
			col[k]++;

			row[j]++;

		}

		int c = 0;

		while(n!=1) {
			int c0 = -1;
			for(int i = 0 ; i<n ; i++) {
				if(col[i] == 0) {
					c0 = i;
					break;
				}
			}
			if(c0 != n-1 && c0 != -1) {
				c++;
				st.append(2+" "+(c0+1)+" "+n+"\n");
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[i][n-1];
					a[i][n-1] = a[i][c0];
					a[i][c0] = y;
				}
				y = col[n-1];
				col[n-1] = col[c0];
				col[c0] = y;

			}
			//display2D(a);
			c0 = -1;
			for(int i = n-2 ; i>=0 ; i-- ) {
				if(row[i] != 0) {
					c0 = i;
					break;
				}
			}

			if(c0 != n-1 && c0 != -1) {
				c++;
				st.append(1+" "+(c0+1)+" "+n+"\n");
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[n-1][i];
					a[n-1][i] = a[c0][i];
					a[c0][i] = y;
				}

				y = row[n-1];
				row[n-1] = row[c0];
				row[c0] = y;
			}
			for(int i = 0 ; i<n-1 ; i++) if(a[n-1][i] == 1) col[i]--;
			/*for(int i : col) System.out.print(i);
			System.out.println();*/
			n--;
			//display2D(a);
		}
		out.println(c);
		out.println(st.toString());

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
		//tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

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

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Diagnol266C {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	int mod = (int)(Math.pow(10,9)+7);

	void solve() {
		int n = ni();
		int a[][] = new int[n][n];
		int col[] = new int[n];
		int row[] = new int[n];
		int f = 0;
		for(int i = 0 ; i<n-1 ; i++) {
			int j = ni()-1;
			int k = ni()-1;
			a[j][k] = 1;
			if(j<=k) f++;
			col[k]++;
			row[j]++;
		}
		if(f == 0) {
			out.println("0");
			return ;
		}
		int c = 0;

		while(n!=1) {
			int c0 = -1;
			for(int i = 0 ; i<n ; i++) {
				if(col[i] == 0) {
					c0 = i;
					break;
				}
			}
			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(2+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[i][n-1];
					a[i][n-1] = a[i][c0];
					a[i][c0] = y;
				}
				y = col[n-1];
				col[n-1] = col[c0];
				col[c0] = y;
			}

			c0 = -1;
			for(int i = n-2 ; i>=0 ; i-- ) {
				if(row[i] != 0 && a[i][n-1] != 1) {
					c0 = i;
					break;
				}
			}

			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(1+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[n-1][i];
					a[n-1][i] = a[c0][i];
					a[c0][i] = y;
				}
				y = row[n-1];
				row[n-1] = row[c0];
				row[c0] = y;
			}
			/*for(int i : col) System.out.print(i);
			System.out.println();*/
			n--;
		}
		System.out.println(c);

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
		//tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

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

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Diagnol266C {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	int mod = (int)(Math.pow(10,9)+7);

	void solve() {
		int n = ni();
		int a[][] = new int[n][n];
		int col[] = new int[n];
		int row[] = new int[n];

		for(int i = 0 ; i<n-1 ; i++) {
			int j = ni()-1;
			int k = ni()-1;
			a[j][k] = 1;
			col[k]++;

			row[j]++;

		}

		int c = 0;

		while(n!=1) {
			int c0 = -1;
			for(int i = 0 ; i<n ; i++) {
				if(col[i] == 0) {
					c0 = i;
					break;
				}
			}
			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(2+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[i][n-1];
					a[i][n-1] = a[i][c0];
					a[i][c0] = y;
				}
				y = col[n-1];
				col[n-1] = col[c0];
				col[c0] = y;

			}
			//display2D(a);
			c0 = -1;
			for(int i = n-2 ; i>=0 ; i-- ) {
				if(row[i] != 0) {
					c0 = i;
					break;
				}
			}

			if(c0 != n-1 && c0 != -1) {
				c++;
				out.println(1+" "+(c0+1)+" "+n);
				int y = 0;
				for(int i = 0 ; i<n ; i++) {
					y = a[n-1][i];
					a[n-1][i] = a[c0][i];
					a[c0][i] = y;
				}

				y = row[n-1];
				row[n-1] = row[c0];
				row[c0] = y;
			}
			for(int i = 0 ; i<n-1 ; i++) if(a[n-1][i] == 1) col[i]--;
			/*for(int i : col) System.out.print(i);
			System.out.println();*/
			n--;
			//display2D(a);
		}
		System.out.println(c);

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
		//tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

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

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


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

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int numCmds = 0;
        StringBuilder cmds = new StringBuilder();

        //get inputs and setup matrix;
        int n = scan.nextInt();
        int[] rows = new int[n + 1];
        int[] cols = new int[n + 1];
        int[] colCount = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            rows[i] = cols[i] = i;
        }
        int[][] matrix = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            matrix[scan.nextInt()][scan.nextInt()] = 1;
        }
        int count;
        for (int i = 1; i <= n; i++) {
            count = 0;
            for (int j = 1; j <= n; j++) {
                if (matrix[j][i] == 1) {
                    count++;
                }
            }
            colCount[i] = count;
        }
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        int temp;
        for (int i = n; i > 1; i--) {
            for (int j = 1; j < i; j++) {
                if (colCount[cols[j]] <= count) {
                    //swap
                    temp = colCount[cols[j]];
                    colCount[cols[j]] = colCount[cols[i]];
                    colCount[cols[i]] = temp;
                    temp = cols[j];
                    cols[j] = cols[i];
                    cols[i] = temp;
                    cmds.append("2 " + i + " " + j + "\n");
                    numCmds++;
                    count++;
                    break;
                }
            }
        }
        //print new array
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        for (int i = n; i > 0; i--) {
            for (int j = n-count; j > 0; j--) {
                if (matrix[rows[j]][cols[i]] == 1) {
                    if ((n - count) != j) {
                        temp = rows[j];
                        rows[j] = rows[n - count];
                        rows[n - count] = temp;
                        cmds.append("1 " + j + " " + (n - count) + "\n");
                        //System.out.println("1 " + j + " " + (n - count) + "\n");
                        numCmds++;
                    }
                    count++; //not sure how to update count without duplicating counts;
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                }
            }
        }
//        for (int e = 1; e <= n; e++) {
//            for (int f = 1; f <= n; f++) {
//                System.out.print(matrix[rows[e]][cols[f]]);
//            }
//            System.out.println("");
//        }
        System.out.println(numCmds);
        System.out.print(cmds);
        out.close();
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


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

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int numCmds = 0;
        StringBuilder cmds = new StringBuilder();

        //get inputs and setup matrix;
        int n = scan.nextInt();
        int[] rows = new int[n + 1];
        int[] cols = new int[n + 1];
        int[] colCount = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            rows[i] = cols[i] = i;
        }
        int[][] matrix = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            matrix[scan.nextInt()][scan.nextInt()] = 1;
        }
        int count;
        for (int i = 1; i <= n; i++) {
            count = 0;
            for (int j = 1; j <= n; j++) {
                if (matrix[j][i] == 1) {
                    count++;
                }
            }
            colCount[i] = count;
        }
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        int temp;
        for (int i = n; i > 1; i--) {
            for (int j = 1; j < i; j++) {
                if (colCount[j] <= count) {
                    //swap
                    temp = colCount[cols[j]];
                    colCount[cols[j]] = colCount[cols[i]];
                    colCount[cols[i]] = temp;
                    temp = cols[j];
                    cols[j] = cols[i];
                    cols[i] = temp;
                    cmds.append("2 " + i + " " + j + "\n");
//                    System.out.println("2 " + i + " " + j);
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                    numCmds++;
                    count++;
                    break;
                }
            }
        }
        //print new array
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        for (int i = n; i > 0; i--) {
            for (int j = n-count; j > 0; j--) {
                if (matrix[rows[j]][cols[i]] == 1) {
                    if ((n - count) != j) {
                        temp = rows[j];
                        rows[j] = rows[n - count];
                        rows[n - count] = temp;
                        cmds.append("1 " + j + " " + (n - count) + "\n");
//                        System.out.println("1 " + j + " " + (n - count) + "\n");
                        numCmds++;
                    }
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                    count++;
                }
            }
        }
//        for (int e = 1; e <= n; e++) {
//            for (int f = 1; f <= n; f++) {
//                System.out.print(matrix[rows[e]][cols[f]]);
//            }
//            System.out.println("");
//        }
        System.out.println(numCmds);
        System.out.print(cmds);
        out.close();
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


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

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int numCmds = 0;
        StringBuilder cmds = new StringBuilder();

        //get inputs and setup matrix;
        int n = scan.nextInt();
        int[] rows = new int[n + 1];
        int[] cols = new int[n + 1];
        int[] colCount = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            rows[i] = cols[i] = i;
        }
        int[][] matrix = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            matrix[scan.nextInt()][scan.nextInt()] = 1;
        }
        int count;
        for (int i = 1; i <= n; i++) {
            count = 0;
            for (int j = 1; j <= n; j++) {
                if (matrix[j][i] == 1) {
                    count++;
                }
            }
            colCount[i] = count;
        }
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        int temp;
        for (int i = n; i > 1; i--) {
            for (int j = 1; j < i; j++) {
                if (colCount[cols[j]] <= count) {
                    //swap
                    temp = colCount[cols[j]];
                    colCount[cols[j]] = colCount[cols[i]];
                    colCount[cols[i]] = temp;
                    temp = cols[j];
                    cols[j] = cols[i];
                    cols[i] = temp;
                    cmds.append("2 " + i + " " + j + "\n");
                    numCmds++;
                    count++;
                    break;
                }
            }
        }
        //print new array
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        for (int i = n; i > 0; i--) {
            for (int j = 1; j <= i; j++) {
                if (matrix[rows[j]][cols[i]] == 1) {
                    if ((n - count) != j && j <= i) {
                        temp = rows[j];
                        rows[j] = rows[n - count];
                        rows[n - count] = temp;
                        cmds.append("1 " + j + " " + (n - count) + "\n");
                        //System.out.println("1 " + j + " " + (n - count) + "\n");
                        numCmds++;
                    }
                    count++;
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                }
            }
        }
//        for (int e = 1; e <= n; e++) {
//            for (int f = 1; f <= n; f++) {
//                System.out.print(matrix[rows[e]][cols[f]]);
//            }
//            System.out.println("");
//        }
        System.out.println(numCmds);
        System.out.print(cmds);
        out.close();
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


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

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int numCmds = 0;
        StringBuilder cmds = new StringBuilder();

        //get inputs and setup matrix;
        int n = scan.nextInt();
        int[] rows = new int[n + 1];
        int[] cols = new int[n + 1];
        int[] colCount = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            rows[i] = cols[i] = i;
        }
        int[][] matrix = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            matrix[scan.nextInt()][scan.nextInt()] = 1;
        }
        int count;
        for (int i = 1; i <= n; i++) {
            count = 0;
            for (int j = 1; j <= n; j++) {
                if (matrix[j][i] == 1) {
                    count++;
                }
            }
            colCount[i] = count;
        }
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        int temp;
        for (int i = n; i > 1; i--) {
            for (int j = 1; j < i; j++) {
                if (colCount[cols[j]] <= count) {
                    //swap
                    temp = colCount[cols[j]];
                    colCount[cols[j]] = colCount[cols[i]];
                    colCount[cols[i]] = temp;
                    temp = cols[j];
                    cols[j] = cols[i];
                    cols[i] = temp;
                    cmds.append("2 " + i + " " + j + "\n");
                    numCmds++;
                    count++;
                    break;
                }
            }
        }
        //print new array
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        for (int i = n; i > 0; i--) {
            for (int j = 1; j <= n; j++) {
                if (matrix[rows[j]][cols[i]] == 1) {
                    if ((n - count) != j && j <= i) {
                        temp = rows[j];
                        rows[j] = rows[n - count];
                        rows[n - count] = temp;
                        cmds.append("1 " + j + " " + (n - count) + "\n");
                        numCmds++;
                    }
                    count++;
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                }
            }
        }
//        for (int e = 1; e <= n; e++) {
//            for (int f = 1; f <= n; f++) {
//                System.out.print(matrix[rows[e]][cols[f]]);
//            }
//            System.out.println("");
//        }
        System.out.println(numCmds);
        System.out.print(cmds);
        out.close();
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


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

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int numCmds = 0;
        StringBuilder cmds = new StringBuilder();

        //get inputs and setup matrix;
        int n = scan.nextInt();
        int[] rows = new int[n + 1];
        int[] cols = new int[n + 1];
        int[] colCount = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            rows[i] = cols[i] = i;
        }
        int[][] matrix = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            matrix[scan.nextInt()][scan.nextInt()] = 1;
        }
        int count;
        for (int i = 1; i <= n; i++) {
            count = 0;
            for (int j = 1; j <= n; j++) {
                if (matrix[j][i] == 1) {
                    count++;
                }
            }
            colCount[i] = count;
        }
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        int temp;
        for (int i = n; i > 1; i--) {
            for (int j = 1; j < i; j++) {
                if (colCount[cols[j]] <= count) {
                    //swap
                    count+= 1-colCount[cols[j]];
                    temp = cols[j];
                    cols[j] = cols[i];
                    cols[i] = temp;
                    cmds.append("2 " + i + " " + j + "\n");
//                    System.out.println("2 " + i + " " + j);
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                    numCmds++;
                    break;
                }
            }
        }
        //print new array
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        for (int i = n; i > 0; i--) {
            for (int j = n-count; j > 0; j--) {
                if (matrix[rows[j]][cols[i]] == 1) {
                    if ((n - count) != j) {
                        temp = rows[j];
                        rows[j] = rows[n - count];
                        rows[n - count] = temp;
                        cmds.append("1 " + j + " " + (n - count) + "\n");
//                        System.out.println("1 " + j + " " + (n - count) + "\n");
                        numCmds++;
                    }
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                    count++;
                }
            }
        }
//        for (int e = 1; e <= n; e++) {
//            for (int f = 1; f <= n; f++) {
//                System.out.print(matrix[rows[e]][cols[f]]);
//            }
//            System.out.println("");
//        }
        System.out.println(numCmds);
        System.out.print(cmds);
        out.close();
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


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

public class Main {

    public static void main(String[] args) {
        FastReader scan = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int numCmds = 0;
        StringBuilder cmds = new StringBuilder();

        //get inputs and setup matrix;
        int n = scan.nextInt();
        int[] rows = new int[n + 1];
        int[] cols = new int[n + 1];
        int[] colCount = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            rows[i] = cols[i] = i;
        }
        int[][] matrix = new int[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            matrix[scan.nextInt()][scan.nextInt()] = 1;
        }
        int count;
        for (int i = 1; i <= n; i++) {
            count = 0;
            for (int j = 1; j <= n; j++) {
                if (matrix[j][i] == 1) {
                    count++;
                }
            }
            colCount[i] = count;
        }
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        int temp;
        for (int i = n; i > 1; i--) {
            for (int j = 1; j < i; j++) {
                if (colCount[j] <= count) {
                    //swap
                    count+= 1-colCount[j];
                    temp = colCount[cols[j]];
                    colCount[cols[j]] = colCount[cols[i]];
                    colCount[cols[i]] = temp;
                    temp = cols[j];
                    cols[j] = cols[i];
                    cols[i] = temp;
                    cmds.append("2 " + i + " " + j + "\n");
//                    System.out.println("2 " + i + " " + j);
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                    numCmds++;
                    break;
                }
            }
        }
        //print new array
//        System.out.println(Arrays.toString(colCount));
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= n; j++) {
//                System.out.print(matrix[rows[i]][cols[j]]);
//            }
//            System.out.println("");
//        }

        count = 0;
        for (int i = n; i > 0; i--) {
            for (int j = n-count; j > 0; j--) {
                if (matrix[rows[j]][cols[i]] == 1) {
                    if ((n - count) != j) {
                        temp = rows[j];
                        rows[j] = rows[n - count];
                        rows[n - count] = temp;
                        cmds.append("1 " + j + " " + (n - count) + "\n");
//                        System.out.println("1 " + j + " " + (n - count) + "\n");
                        numCmds++;
                    }
//                    System.out.println(count);
//                    for (int e = 1; e <= n; e++) {
//                        for (int f = 1; f <= n; f++) {
//                            System.out.print(matrix[rows[e]][cols[f]]);
//                        }
//                        System.out.println("");
//                    }
                    count++;
                }
            }
        }
//        for (int e = 1; e <= n; e++) {
//            for (int f = 1; f <= n; f++) {
//                System.out.print(matrix[rows[e]][cols[f]]);
//            }
//            System.out.println("");
//        }
        System.out.println(numCmds);
        System.out.print(cmds);
        out.close();
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();

        int array[][] = new int[x][x];

        for (int i = 0; i < x - 1; i++) {
            array[in.nextInt() - 1][in.nextInt() - 1] = 1;
        }
        int times = 0;
        String report = "";

        for (int i = x-1 ; i > 0; i--) {
            int colm = is_empty_colm((array), i);
            if (colm != -1 && colm != i) {
                for (int j = 0; j < x-1 ; j++) {
                    int temp = array[j][i];
                    array[j][i] = array[j][colm];
                    array[j][colm] = temp;
                }

                report += (2 + " " + (i + 1) + " " + (colm+1) + "\n");
                times++;
            }

            int row = is_empty_row((array), i);

            if (row != -1 && row != i) {

                for (int j = 0; j < x-1 ; j++) {

                    int temp = array[i][j];
                    array[i][j] = array[row ][j];
                    array[row][j] = temp;

                }

                 report += (1 + " " + (i + 1) + " " + (row+1)+ "\n");
                times++;
            }

        }

        System.out.println(times);
        System.out.println(report);
//        for (int i = 0; i < array.length; i++) {
//            for (int j = 0; j < array[0].length; j++) {
//                System.out.print(array[i][j]);
//            }
//            System.out.println("");
//        }
    }

    public static int is_empty_row(int x[][], int row) {

        for (int i = 0; i <= row; i++) {
            for (int j = 0; j <= row; j++) {
                if (x[i][j] == 1) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static int is_empty_colm(int x[][], int col) {
        for (int i = 0; i <= col; i++) {
            boolean flag = true;
            for (int j = 0; j <= col; j++) {
                if (x[j][i] == 1) {
                    flag = false;
                    break;
                }
            }
            if (flag) { // first empty colm
                return i;
            }
        }
        return -1;
    }

}


//could not solve :(

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

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

	static class TaskC {
		public void solve (int testNumber, InputReader in, PrintWriter out) {
			/*
			 * wtf? difficulty 6 😱 ? The only weak point seems to be the fact that number of '1' is <n so you can keep
			 * them on
			 * different cols or different rows if you want. I guess best will be to keep them on both different rows and
			 * differnt cols
			 * but zei duita ek row te ba ek col e ache tader jiboneo alada korte parbi na. kajei beshi paknami kore lav nai
			 * . One rough
			 * plan is to: row gulake sort kore new oi row te 1 er shonkhyar ascending order erpor col gulake sort kore new
			 * ulta vabe
			 * but the problem is when zokhon dui row ba col er shoman hobe tokhon dekha lagbe kontar shuru kothay. Even if
			 * this method
			 * is correct the biggest problem is how the hell am I gonna output the number of steps before performing the
			 * steps as string
			 * concat is very much slow. One superb way is to make an string array.
			 */
			int n = in.nextInt ();
			int[] x = new int[n+5], y = new int[n+5], cntx = new int[n+5], cnty = new int[n+5], mnx = new int[n+5], mny =
																															new int[n+
																																			5];
			for (int i = 0; i<n+4; i++) {
				Arrays.fill (mnx, Integer.MAX_VALUE);
				Arrays.fill (mny, Integer.MAX_VALUE);
			}
			for (int i = 0; i<n-1; i++) {
				x[i] = in.nextInt ();
				y[i] = in.nextInt ();
				cntx[--x[i]]++;
				cnty[--y[i]]++;
				mny[x[i]] = Math.min (mny[x[i]], y[i]);
			}

			int[][] mtrx = new int[n+5][n+5];
			for (int i = 0; i<n-1; i++) {
				mtrx[x[i]][y[i]] = 1;
			}

		/*System.out.println ("initial matrix:");
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				System.out.print (mtrx[i][j]+" ");
			}
			System.out.println ();
		}*/

			int ns = 0;
			String[] res = new String[100000];
			for (int i = 0; i<n-1; i++) {
				int mnidx = i;
				for (int j = i+1; j<n; j++) {
					if (cntx[j]<cntx[mnidx] || (cntx[j] == cntx[mnidx] && mny[j]<mny[mnidx])) {
//					System.out.println ("dhuksi row "+j+" "+mnidx+" "+cntx[j]+" "+cntx[mnidx]+" "+mny[j]+" "+mny[mnidx]);
						mnidx = j;
					}
				}
				if (mnidx != i) {
					cntx[i] = (cntx[i]^cntx[mnidx])^(cntx[mnidx] = cntx[i]);
					mny[i] = (mny[i]^mny[mnidx])^(mny[mnidx] = mny[i]);
					res[ns++] = ("1 "+(i+1)+" "+(mnidx+1));

					for (int j = 0; j<n; j++) {
						mtrx[i][j] = (mtrx[i][j]^mtrx[mnidx][j])^(mtrx[mnidx][j] = mtrx[i][j]);
					}
				}
			}

		/*System.out.println ("row operation shesh");
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				System.out.print (mtrx[i][j]+" ");
			}
			System.out.println ();
		}*/

			for (int i = 0; i<n; i++) {
				for (int j = 0; j<n; j++) {
					if (mtrx[j][i] == 1) {
						mnx[i] = j;
//					System.out.println ("mnx of "+i+": "+j);
						break;
					}
				}
			}

			for (int i = 0; i<n-1; i++) {
				int mxidx = i;
				for (int j = i+1; j<n; j++) {
					if (cnty[j]>cnty[mxidx] || (cnty[j] == cnty[mxidx] && mnx[j]<mnx[mxidx])) {
//					System.out.println ("dhuksi col "+j+" "+mxidx+" "+cnty[j]+" "+cnty[mxidx]+" "+mnx[j]+" "+mnx[mxidx]);
						mxidx = j;
					}
				}
				if (mxidx != i) {
					cnty[i] = (cnty[i]^cnty[mxidx])^(cnty[mxidx] = cnty[i]);
					mnx[i] = (mnx[i]^mnx[mxidx])^(mnx[mxidx] = mnx[i]);
					res[ns++] = ("2 "+(i+1)+" "+(mxidx+1));

					for (int j = 0; j<n; j++) {
						mtrx[j][i] = (mtrx[j][i]^mtrx[j][mxidx])^(mtrx[j][mxidx] = mtrx[j][i]);
					}
				}
			}
			out.println (ns);
			for (int i = 0; i<ns; i++) {
				out.println (res[i]);
			}

		/*System.out.println ("final answer");
		for (int i = 0; i<n; i++) {
			for (int j = 0; j<n; j++) {
				System.out.print (mtrx[i][j]+" ");
			}
			System.out.println ();
		}*/
		}

	}

	static class InputReader implements AutoCloseable {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

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

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

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

		public void close () throws Exception {
			reader.close ();
		}

	}
}