You are given a square matrix consisting of *n* rows and *n* columns. We assume that the rows are numbered from 1 to *n* from top to bottom and the columns are numbered from 1 to *n* from left to right. Some cells (*n* - 1 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can apply the following operations to the matrix:
 1.  Swap *i*-th and *j*-th rows of the matrix; 1.  Swap *i*-th and *j*-th columns of the matrix. 
You are asked to transform the matrix into a special form using these operations. In that special form all the ones must be in the cells that lie below the main diagonal. Cell of the matrix, which is located on the intersection of the *i*-th row and of the *j*-th column, lies below the main diagonal if *i* &gt; *j*.
The first line contains an integer *n* (2 ≤ *n* ≤ 1000) — the number of rows and columns. Then follow *n* - 1 lines that contain one's positions, one per line. Each position is described by two integers *x*<sub class="lower-index">*k*</sub>, *y*<sub class="lower-index">*k*</sub> (1 ≤ *x*<sub class="lower-index">*k*</sub>, *y*<sub class="lower-index">*k*</sub> ≤ *n*), separated by a space. A pair (*x*<sub class="lower-index">*k*</sub>, *y*<sub class="lower-index">*k*</sub>) means that the cell, which is located on the intersection of the *x*<sub class="lower-index">*k*</sub>-th row and of the *y*<sub class="lower-index">*k*</sub>-th column, contains one.

It is guaranteed that all positions are distinct.
def solve():
    n = int(input())
    dd = [[0] * (n) for _ in range(n)]
    for i in range(n - 1):
        a = input()
        x, y = a.split()
        dd[int(x) - 1][int(y) - 1] = 1
    flag = False
    for i in range(n - 1, -1, -1):
        for j in range(i + 1):
            if not any([x[j] for x in dd]):
                if j != i:
                    for cur in range(i):
                        temp = dd[cur][j]
                        dd[cur][j] = dd[cur][i]
                        dd[cur][i] = temp
                    print(2, j + 1, i + 1)
                    flag = True
                break
        for k in range(i, -1, -1):
            if dd[k].count(1) >= 1:
                if k != i:
                    for cur in range(i):
                        temp = dd[k][cur]
                        dd[k][cur] = dd[i][cur]
                        dd[i][cur] = temp
                    print(1, k + 1, i + 1)
                    flag = True
                break
    if not flag:
        print(0)


# main
if __name__ == "__main__":
    solve()
