Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem. 

Allen's future parking lot can be represented as a rectangle with 4 rows and n (n ≤ 50) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having k (k ≤ 2n) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places.

<image> Illustration to the first example.

However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space. 

Allen knows he will be a very busy man, and will only have time to move cars at most 20000 times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important.

Input

The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n), representing the number of columns and the number of cars, respectively.

The next four lines will contain n integers each between 0 and k inclusive, representing the initial state of the parking lot. The rows are numbered 1 to 4 from top to bottom and the columns are numbered 1 to n from left to right.

In the first and last line, an integer 1 ≤ x ≤ k represents a parking spot assigned to car x (you can only move this car to this place), while the integer 0 represents a empty space (you can't move any car to this place).

In the second and third line, an integer 1 ≤ x ≤ k represents initial position of car x, while the integer 0 represents an empty space (you can move any car to this place).

Each x between 1 and k appears exactly once in the second and third line, and exactly once in the first and fourth line.

Output

If there is a sequence of moves that brings all of the cars to their parking spaces, with at most 20000 car moves, then print m, the number of moves, on the first line. On the following m lines, print the moves (one move per line) in the format i r c, which corresponds to Allen moving car i to the neighboring space at row r and column c.

If it is not possible for Allen to move all the cars to the correct spaces with at most 20000 car moves, print a single line with the integer -1.

Examples

Input

4 5
1 2 0 4
1 2 0 4
5 0 0 3
0 5 0 3


Output

6
1 1 1
2 1 2
4 1 4
3 4 4
5 3 2
5 4 2


Input

1 2
1
2
1
2


Output

-1


Input

1 2
1
1
2
2


Output

2
1 1 1
2 4 1

Note

In the first sample test case, all cars are in front of their spots except car 5, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most 20000 will be accepted.

In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible.
"""
http://codeforces.com/contest/996/problem/C
"""

class CarAlgorithm:
    def __init__(self, n, k, parking):
        self.n = n
        self.k = k
        self.parking = parking
        self._steps = []
        self._done = False
        for i in range(4):
            assert len(parking[i]) == n, "%s != %s" % (len(parking[i]), n)


    def do(self):
        """
        1) загоянем все тривиальные машины
        2) ищем пробел (если нет, то нет решения)

        3) для каждой машины рассчитываем минимальной путь до парковки
        4) выбираем машину с минимальным расстоянием до парковки
        """
        if self._done:
            return self._steps
        self._done = True
        n, k, parking = self.n, self.k, self.parking
        car_target_cells = {}
        # solve trivial cars
        for park_str, car_str in [(0, 1), (3, 2)]:
            for i in range(n):
                car_number = parking[park_str][i]
                if car_number == 0:
                    continue
                elif parking[car_str][i] == car_number:
                    self._move_car(parking, car_str, i, park_str, i)
                else:
                    car_target_cells[car_number] = (park_str, i)
                # car_number = parking[3][i]
                # if car_number == 0:
                #     continue
                # elif parking[2][i] == car_number:
                #     self.move_car(parking, 2, i, 3, i)
                # else:
                #     car_target_cells[car_number] = (3, i)
        # print(car_target_cells)
        while True:
            # find shortest path for all cars
            # choose car with minimal shortest path
            # find free cell
            target_shortest_path = None
            target_car_cell = None
            target_dst_str, target_dst_col = None, None
            free_cell = None
            for j in range(1, 3):
                for i in range(n):
                    if parking[j][i] == 0:
                        if not free_cell:
                            free_cell = j, i
                    else:
                        cur_car = parking[j][i]
                        target_str, target_col = car_target_cells[cur_car]
                        cur_shortest_path = find_path(j, i, target_str, target_col)
                        if target_shortest_path is None or len(cur_shortest_path) < len(target_shortest_path):
                            target_shortest_path = cur_shortest_path
                            target_car_cell = j, i
                            target_dst_str, target_dst_col = target_str, target_col

            # if target_car_cell:
            #     print("choose car %s" % parking[target_car_cell[0]][target_car_cell[1]])

            if target_shortest_path is None:
                # car is on the road is not found
                return self._steps

            # print("shortest path %s" % target_shortest_path)

            # move car to cell before dst cell
            car_cell_str, car_cell_col = target_car_cell
            for path_next_cell_str, path_next_cell_col in target_shortest_path:
                if parking[path_next_cell_str][path_next_cell_col] != 0:
                    # move free cell to next cell from path
                    if not free_cell:
                        self._steps = -1
                        return self._steps
                    free_cell_str, free_cell_col = free_cell
                    # print(bool(free_cell_str == car_cell_str == path_next_cell_str))
                    # print(free_cell_col, car_cell_col, path_next_cell_col)
                    if free_cell_str == car_cell_str == path_next_cell_str and (
                            free_cell_col < car_cell_col < path_next_cell_col or path_next_cell_col < car_cell_col < free_cell_col
                    ):
                        # .****сx or xc****.
                        # |_____|    |_____|
                        # free cell can not be moved on straight line
                        # change free cell string
                        if free_cell_str == 1:
                            if parking[2][free_cell_col] != 0:
                                self._move_car(parking, 2, free_cell_col, 1, free_cell_col)
                            free_cell_str = 2
                        else:  # free_cell_str == 2
                            if parking[1][free_cell_col] != 0:
                                self._move_car(parking, 1, free_cell_col, 2, free_cell_col)
                            free_cell_str = 1
                    # move free cell on horizontal straight line
                    free_cell_step = 1 if free_cell_col < path_next_cell_col else -1
                    for free_cell_next_col in range(free_cell_col + free_cell_step, path_next_cell_col + free_cell_step, free_cell_step):
                        if parking[free_cell_str][free_cell_next_col] != 0:
                            self._move_car(parking, free_cell_str, free_cell_next_col, free_cell_str, free_cell_col)
                        free_cell_col = free_cell_next_col
                    # move free cell on vertical straight line if needed
                    if (free_cell_str, path_next_cell_str) in [(1, 2), (2, 1)]:
                        self._move_car(parking, path_next_cell_str, path_next_cell_col, free_cell_str, free_cell_col)
                        free_cell = path_next_cell_str, path_next_cell_col
                self._move_car(parking, car_cell_str, car_cell_col, path_next_cell_str, path_next_cell_col)
                car_cell_str, car_cell_col = path_next_cell_str, path_next_cell_col
            self._move_car(parking, car_cell_str, car_cell_col, target_dst_str, target_dst_col)

    def _move_car(self, parking, from_str, from_col, to_str, to_col):
        car_number = parking[from_str][from_col]
        # print("%s %s %s" % (car_number, to_str, to_col))
        self._steps.append((car_number, to_str+1, to_col+1))
        # print("%s %s %s" % (car_number, to_str+1, to_col+1))
        # print("%s %s %s %s" % (car_number, to_str+1, to_col+1, parking))
        parking[to_str][to_col] = parking[from_str][from_col]
        parking[from_str][from_col] = 0

    class Cell:
        def __init__(self, str_n: int, col_n: int):
            self.str = str_n
            self.col = col_n


def find_path(from_str, from_col, to_str, to_col):
    """
    return internal path between from_cell and to_cell (borders are not included)
    """
    str_direct = 1 if from_col < to_col else -1
    path = [
        (from_str, i) for i in range(
            from_col + str_direct, to_col + str_direct, str_direct
        )
    ]
    if from_str == 1 and to_str == 3:
        path.append((2, to_col))
    elif from_str == 2 and to_str == 0:
        path.append((1, to_col))
    # col_direct = 1 if from_str < to_str else -1
    # path.extend([
    #     (i, to_col) for i in range(
    #         from_str + col_direct, to_str + col_direct, col_direct
    #     )
    # ])
    # print(from_str, from_col, path)
    return path

def do():
    n, k = [int(str_i) for str_i in input().split()]
    p = [
        [int(str_i) for str_i in input().split()]
        for _ in range(4)
    ]
    steps = f(p)
    if isinstance(steps, list):
        if len(steps) > 20000:
            print(-1)
        else:
            print(len(steps))
            for s in steps:
                print("%s %s %s" % s)
    else:
        print(steps)

def f(square: list):
    assert len(square) == 4
    n = len(square[0])
    for s in square:
        assert len(s) == n

    steps = []
    free_cell_str, free_cell_col = None, None
    all_cars_are_parked = True
    # trivial parking
    for from_str, to_str in [(1, 0), (2, 3)]:
        for j in range(n):
            if square[from_str][j] == 0:
                free_cell_str, free_cell_col = from_str, j
            elif square[from_str][j] == square[to_str][j]:
                move_car(steps, square, from_str, j, to_str, j)
                free_cell_str, free_cell_col = from_str, j
            else:
                all_cars_are_parked = False
    if not all_cars_are_parked and not free_cell_str and not free_cell_col:
        return -1
    while not all_cars_are_parked:
        all_cars_are_parked = True
        start_str, start_col = free_cell_str, free_cell_col
        while True:
            prev_str, prev_col = prev(n, free_cell_str, free_cell_col)
            # print("1", prev_str, prev_col,free_cell_str, free_cell_col)
            if prev_col == -1:
                exit()
            car_number = square[prev_str][prev_col]
            # print("2", prev_str, prev_col,free_cell_str, free_cell_col)
            if car_number != 0:
                # move car to free cell
                move_car(steps, square, prev_str, prev_col, free_cell_str, free_cell_col)
                car_new_str, car_new_col = free_cell_str, free_cell_col
                # check that car is opposite of his parking cell
                if car_new_str == 1:
                    parking_str = 0
                else: # car_new_str == 2
                    parking_str = 3
                if square[parking_str][car_new_col] == car_number:
                    move_car(steps, square, car_new_str, car_new_col, parking_str, car_new_col)
                else:
                    all_cars_are_parked = False
            # print("3", prev_str, prev_col,free_cell_str, free_cell_col)
            free_cell_str, free_cell_col = prev_str, prev_col
            # print("4", prev_str, prev_col, free_cell_str, free_cell_col)
            if (free_cell_str, free_cell_col) == (start_str, start_col):
                break
    return steps





def move_car(steps, square, from_str, from_col, to_str, to_col):
    car_number = square[from_str][from_col]
    # print("%s %s %s" % (car_number, to_str, to_col))
    steps.append((car_number, to_str + 1, to_col + 1))
    # print("%s %s %s" % (car_number, to_str+1, to_col+1))
    # print("%s %s %s %s" % (car_number, to_str+1, to_col+1, parking))
    square[to_str][to_col] = square[from_str][from_col]
    square[from_str][from_col] = 0

def prev(n, cur_str, cur_col):
    if n == 1:
        return 2 if cur_str == 1 else 1, 0
    elif cur_col == 0:
        return 1, 0 if cur_str == 2 else 1
    elif cur_col == n - 1:
        return 2, n - 1 if cur_str == 1 else n - 2
    else:
        return cur_str, cur_col + 1 if cur_str == 1 else cur_col - 1



def test():
    r = f([[1],[1],[2],[2]])
    assert r == [(1,1,1), (2,4,1)], r

    r = f([[1], [2], [1], [2]])
    assert r == -1, r

    r = f([[1,2], [2,3], [1,0], [3,0]])
    assert r == [(1,3,2), (2,3,1), (3,2,1), (1,2,2), (2,3,2), (3,3,1), (3,4,1), (1,2,1), (1,1,1), (2,2,2), (2,1,2)], r

    r = f([[1,2], [3,1], [0,2], [3,0]])
    assert r == [(3,3,1), (3,4,1), (1,2,1), (1,1,1), (2,2,2), (2,1,2)], r



# test()
do()
