p00091 Blur_16137
There is a "cloth" of 10 × 10 squares as shown in Fig. 1, and the squares are indicated by a pair of X-coordinate and Y-coordinate values ​​as shown in (1 and 2). The coordinate value is an integer starting from 0. For example, the coordinates of ◎ in Figure 1 are (1, 2). Dye is made by adding dye to this "cloth" little by little. There are three sizes of dripping dye drops, "Large", "Medium", and "Small", and the surroundings are colored as shown in Fig. 1 centering on the squares where the dye drops have fallen. In Fig. 1, ☆ is the center and ○ is the color bleeding range.

<image>


"Cloth" is initially "straight", that is, every square has a value of 0 that indicates the color depth. The value increases by 1 for each drop of dye. If "Small" falls to (1, 2) and "Medium" falls to (3, 2), the value of each square will be as shown on the left in Fig. 2. Since the dye is wasteful, it is not supposed to be removed so that the bleeding area on the right side of Fig. 2 sticks out of the cloth. Also, multiple dyes may be applied to the same place.

<image>


After repeating this process several times, a wonderful pattern emerged on the cloth, but unfortunately I inadvertently forgot to record the progress of the work. I can't remember at all, but I barely remembered the number of drops of dye I dropped. You have to reproduce the wonderful dyeing. Create a program that reads the data of wonderful dyes and outputs where and what kind of dye was applied. The number of drops of dye dropped should be 12 or less.



input

The input format is as follows:

The first line gives the number of drops of dye n dropped. The next to 10 lines are given the color strength of each coordinate, separated by blanks.

output

The output consists of n lines. "Large" of the dye drop is represented by 3, "Medium" is represented by 2, and "Small" is represented by 1, and the X coordinate, Y coordinate, and drop size of each dropped dye are output on one line separated by a blank. please.

The dyes can be applied in any order.

Example

Input

2
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 1 1 0 0 0 0 0
0 0 0 1 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0


Output

3 2 1
8 4 2
B,M,S = 13,9,5
dx = [ 0, 0, 1, 0,-1, 1, 1,-1,-1, 0, 2, 0,-2]
dy = [ 0,-1, 0, 1, 0,-1, 1, 1,-1, 2, 0,-2, 0]
def isOnCloth(x,y):
    return 0<=x<10 and 0<=y<10
def soak(cloth,x,y,ink):
    for i in xrange(ink):
        cloth[y+dy[i]][x+dx[i]] -= 1
def drop(cloth,x,y,ink):
    for i in xrange(ink):
        cloth[y+dy[i]][x+dx[i]] += 1
def canSoak(cloth,x,y,ink):
    return all([isOnCloth(x+dx[i],y+dy[i]) and cloth[y+dy[i]][x+dx[i]]>0 for i in xrange(ink)])
def DFS(cloth,ink_set,cur):
    if len(ink_set)==0:
        return []
    for i in xrange(cur,100):
        if not cloth[i/10][i%10] == 0:
            break
        cur += 1
    for ink in set(ink_set):
        for i in xrange(ink):
            cx,cy = cur%10+dx[i],cur/10+dy[i]
            if isOnCloth(cx,cy) and cloth[cy][cx]>0:
                if canSoak(cloth,cx,cy,ink):
                    soak(cloth,cx,cy,ink)
                    ink_set.remove(ink)
                    result = DFS(cloth,ink_set,cur)
                    if not result == False:
                        result.append([cx,cy,ink])
                        return result
                    ink_set.append(ink)
                    drop(cloth,cx,cy,ink)
    return False
ink_set = [B,S]
clothA = [[0,0,0,0,0,0,0,0,0,0],
         [0,0,1,0,0,0,0,0,0,0],
         [0,1,1,1,0,0,0,0,0,0],
         [1,1,1,1,1,0,0,0,0,0],
         [0,1,1,1,0,0,0,0,0,0],
         [0,0,1,0,0,0,0,0,0,0],
         [0,0,0,0,0,0,0,0,0,0],
         [0,0,0,0,0,0,1,0,0,0],
         [0,0,0,0,0,1,1,1,0,0],
         [0,0,0,0,0,0,1,0,0,0],
         [0,0,0,0,0,0,0,0,0,0],]
clothB = [[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,1,0,0,0,0,0,0,0],
          [0,1,1,1,0,0,0,0,0,0],
          [0,0,1,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],]
import itertools
n = input()
cloth = []
for u in xrange(10):
    cloth.append(map(int,raw_input().split(" ")))
su = sum([sum(cloth[i]) for i in xrange(10)])
ink_sets = [list(a) for a in itertools.combinations_with_replacement([0,13,9,5],n) if sum(a) == su]
for ink_set in ink_sets:
    pass
    result = DFS(cloth,ink_set,0)
    if not result == False:
        break
dic = {B:3,M:2,S:1}
for r in result:
    print "{} {} {}".format(r[0],r[1],dic[r[2]])