Chef has found a new game and now he wants you to help him to get as much points as possible. 
Rules of the game: There are different types of game pieces -  geometric shapes composed of some amount of square blocks. In the picture below you can see all the types of figures and enumeration. 
The playing field is 10 cells width and 10 cells height. On each step of the game you are given exactly three game pieces. After that you need to put each of them to the game field such that after your move no two figures on the field are overlapped(you cannot rotate figures). If your move results in one or more horizontal or/and vertical lines of 10 units without gaps, those lines disappear. Notice that you put these three figures one by one and if you place the first figure and there are some lines ready to disappear, then they will disappear and only after that you place other figures.  
The game ends when you can't put no more figures on the game field.

-----Input-----
Each line of input contains three integers figure1, figure2 , figure3 denoting the type of the figures appeared on this step. If the game has ended - in the next line of input will be "-1 -1 -1". 

-----Interaction with the judge-----
In each step you should read from the standard input all information about figures that appear in this step. After receiving this input, you should print one line containing nine space-separated parameters id1, r1, c1, id2, r2, c2, id3, r3 and c3. Integers {id1, id2, id3} is the permutation of {1, 2, 3} and denote the order in which you will put these three figures. Integer ri denotes the number of the row of the lowest block of idith figure after you put it and ci denotes the number of the column of the leftmost block of idith figure after you put it. The rows are numbered from 1 to 10 from top to bottom and columns are numbered from 1 to 10 from left to right. Remember to flush the output after every line you print.
To finish the game(if you don't know where to put figures or it's impossible to put some figures) you need to output "-1" for figures you don't know where to put. For example, if on some move you don't know how to place all three figures, you need to output nine '-1"s as describing of all three figures. But if you can place, for example, only second figure, you need to output next numbers: "2 r1 c1 -1 -1 -1 -1 -1 -1". When judge reads "-1"s as describing of some figure, it means that the game ends at this step and then judge will output only "-1 -1 -1" as sign of finishing the game. 

-----Constraints-----
- 1 ≤ figurei ≤ 19
- Total amount of steps of the game does not exceed 5 * 104 

-----Scoring-----
- For each test case, your score will be the sum of areas(amount of square blocks figure consists) of figures that you correctly place in the playing field. Your goal is to maximise this score.
- Also there are some bonuses: if after your move exactly x row(s) and y column(s) will disappear - your score for this test will be increased by x2 + y2 + 5 * x *y and by 500 if after your move the field will be empty. 
- Your total score for the problem will be the sum of scores on all the test cases.
- Your solution will be tested only on 20% of the test files during the contest and will be re-judged against 100% after the end of competition.
- The game ends when you output "-1"s as describing of placing some figure(what means you want to finish the game) or total number of moves reached 5 * 104. In both cases the judge will output "-1 -1 -1" as a sing of finishing of the game.
- You will get WA verdict if you output incorrect data or some figures overlap. Incorrect data means that there is no way to put this figure at the place you output or you output completely incorrect data: idi ∉ {1, 2, 3},  {id1, id2, id3} is not the permutation of {1, 2, 3}, r ∉ [1..10] or c ∉ [1..10].
- If you passed all 5 * 104 steps of the game, the next line of input will be "-1 -1 -1" and your result will be the score you got.

-----Test data generation-----
For each test file the probabilities of appearing each figure are manually chosen.

-----Example-----
Input:
8 3 11
6 14 12
5 10 11
5 7 11
16 19 1
-1 -1 -1

Output:
3 6 5 2 2 2 1 10 8
1 4 8 2 6 1 3 7 2
1 5 8 3 4 8 2 6 8
3 9 8 2 10 7 1 1 6
3 10 8 2 8 3 -1 -1 -1

-----Explanation-----
In this test case your score will be 74 = 66 (for areas of figures) + 8 (bonus score).
On the fifth move the player decided to finish the game and output three "-1"s as the describing of placing the last figure on this move.

Difficulty: interview

Starter code:

Solutions:
import sys

blocks = {}

for i in range(1, 10):
    blocks[i] = [(0, 0)]
for i in range(2, 10, 2):
    for j in range(1, i / 2 + 1):
        blocks[i].append((j, 0))
        blocks[i + 1].append((0, j))
# print blocks
blocks[10] = [(0, 0), (0, 1), (1, 0), (1, 1)]
blocks[11] = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
blocks[12] = [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)]
blocks[13] = [(0, 2), (1, 2), (2, 0), (2, 1), (2, 2)]
blocks[14] = [(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)]
blocks[15] = [(0, 0), (0, 1), (0, 2), (1, 0), (2, 0)]
blocks[16] = [(0, 0), (0, 1), (1, 0)]
blocks[17] = [(0, 0), (0, 1), (1, 1)]
blocks[18] = [(0, 1), (1, 0), (1, 1)]
blocks[19] = [(0, 0), (1, 0), (1, 1)]

grid = [['.'] * 10] * 10
# print grid

id1, id2, id3 = list(map(int, input().split()))
while not (id1 == id2 == id3 == -1):
    print('-1 -1 -1 -1 -1 -1 -1 -1 -1')
    sys.stdout.flush()
    id1, id2, id3 = list(map(int, input().split()))



import fileinput
import sys
from collections import Counter
from math import sqrt

def get_input():
    return [line for line in fileinput.input()]

class NewGame2:
    N = 10
    map = [[0 for i2 in range(0, N)] for j2 in range(0, N)]
    score = 0
    moves = 0
    debug = False

    def __init__(self):
        pass

    def play(self, pieces):
        clear = False
        # clear = True
        if self.moves > 3:
            return '-1 -1 -1 -1 -1 -1 -1 -1 -1'

        res = self.getMoves(pieces)

        placed = 0

        gameOver = False
        for i in range(0, len(res)):
            if res[i] == -1:
                gameOver = True

        if not gameOver:
            clearRows = 0
            clearColumns = 0

            for i in range(0, len(res), 3):
                p = self.defi[pieces[res[i]-1]]
                posy = res[i+1] - len(p)
                posx = res[i+2] - 1

                for py in range(0, len(p)):
                    for px in range(0, len(p[0])):
                        if p[py][px] > 0:
                            self.map[posy+py][posx+px] = pieces[res[i]-1] +1;
                            placed += 1

                # clear
                rows = [False for i in range(0, self.N)]
                columns = [False for i in range(0, self.N)]

                for y in range(0, self.N):
                    fill = 0
                    for x in range(0, self.N):
                        if self.map[y][x] > 0:
                            fill += 1
                    if fill == self.N:
                        rows[y] = True
                        clearRows += 1

                for x in range(0, self.N):
                    fill = 0
                    for y in range(0, self.N):
                        if self.map[y][x] > 0:
                            fill += 1
                    if fill == self.N:
                        columns[y] = True
                        clearColumns += 1

                for y in range(0, self.N):
                    for x in range(0, self.N):
                        if (rows[y] or columns[x]) and clear:
                            self.map[y][x] = 0

            size = 0
            for y in range(0, self.N):
                for x in range(0, self.N):
                    if self.map[y][x] > 0:
                        size += 1

            if size == 0:
                self.score += 500

            self.score += placed
            self.score += clearColumns * clearColumns + clearRows * clearRows + (5 * clearRows * clearColumns)
            self.moves += 1

        output = "";
        for i in range(0, len(res)):
            if (i > 0):
                output += " "

            output += str(res[i])

        return output

    def getMoves(self, pieces):
        res = [-1 for i in range(0, 9)]
        tMap = [[0 for i2 in range(0, self.N)] for j2 in range(0, self.N)]

        for y in range(0, self.N):
            for x in range(0, self.N):
                tMap[y][x] = self.map[y][x]

        for i in range(0, len(pieces)):
            p = self.defi[pieces[i]]

            found_move = False
            for y in range(0, self.N):
                for x in range(0, self.N):
                    if not found_move:
                        valid = True
                        for py in range(0, len(p)):
                            for px in range(0, len(p[0])):
                                if valid and (y+py >= self.N or x+px >= self.N or (p[py][px] > 0 and tMap[y+py][x+px] != 0)):
                                    valid = False
                                    break
                        if (valid):
                            for py in range(0, len(p)):
                                for px in range(0, len(p[0])):
                                    if (p[py][px] > 0):
                                        tMap[y+py][x+px] = pieces[i] +1

                            res[i*3 + 0] = i+1
                            res[i*3 + 1] = y+len(p)
                            res[i*3 + 2] = x+1
                            found_move = True
                            break

        return res

    defi = [
        [
            [1],
        ],
        [
            [1],
            [1],
        ],
        [
            [1, 1],
        ],
        [
            [1],
            [1],
            [1],
        ],
        [
            [1, 1, 1],
        ],
        [
            [1],
            [1],
            [1],
            [1],
        ],
        [
            [1, 1, 1, 1],
        ],
        [
            [1],
            [1],
            [1],
            [1],
            [1],
        ],
        [
            [1, 1, 1, 1, 1],
        ],
        [
            [1, 1],
            [1, 1],
        ],
        [
            [1, 1, 1],
            [1, 1, 1],
            [1, 1, 1],
        ],
        [
            [1, 1, 1],
            [0, 0, 1],
            [0, 0, 1],
        ],
        [
            [0, 0, 1],
            [0, 0, 1],
            [1, 1, 1],
        ],
        [
            [1, 0, 0],
            [1, 0, 0],
            [1, 1, 1],
        ],
        [
            [1, 1, 1],
            [1, 0, 0],
            [1, 0, 0],
        ],
        [
            [1, 1],
            [1, 0],
        ],
        [
            [1, 1],
            [0, 1],
        ],
        [
            [0, 1],
            [1, 1],
        ],
        [
            [1, 0],
            [1, 1],
        ],
    ]


class JUNE16:
    def __init__(self):
        self.CHNWGM()

    def CHNWGM(self):
        game = NewGame2()
        while True:
            a = [int(x)-1 for x in input().split()]
            # print "in: %s" % a
            if a[0] < 0:
                return
            print(game.play(a))

            sys.stdout.flush()
            sys.stdin.flush()


def __starting_point():
    JUNE16()

__starting_point()


import fileinput
import sys
from collections import Counter
from math import sqrt

def get_input():
    return [line for line in fileinput.input()]

class NewGame2:
    N = 10
    map = [[0 for i2 in range(0, N)] for j2 in range(0, N)]
    score = 0
    moves = 0
    debug = False

    def __init__(self):
        pass

    def play(self, pieces):
        clear = False
        clear = True
        if self.moves > 3:
            return '-1 -1 -1 -1 -1 -1 -1 -1 -1'

        res = self.getMoves(pieces)

        placed = 0

        gameOver = False
        for i in range(0, len(res)):
            if res[i] == -1:
                gameOver = True

        if not gameOver:
            clearRows = 0
            clearColumns = 0

            for i in range(0, len(res), 3):
                p = self.defi[pieces[res[i]-1]]
                posy = res[i+1] - len(p)
                posx = res[i+2] - 1

                for py in range(0, len(p)):
                    for px in range(0, len(p[0])):
                        if p[py][px] > 0:
                            self.map[posy+py][posx+px] = pieces[res[i]-1] +1;
                            placed += 1

                # clear
                rows = [False for i in range(0, self.N)]
                columns = [False for i in range(0, self.N)]

                for y in range(0, self.N):
                    fill = 0
                    for x in range(0, self.N):
                        if self.map[y][x] > 0:
                            fill += 1
                    if fill == self.N:
                        rows[y] = True
                        clearRows += 1

                for x in range(0, self.N):
                    fill = 0
                    for y in range(0, self.N):
                        if self.map[y][x] > 0:
                            fill += 1
                    if fill == self.N:
                        columns[y] = True
                        clearColumns += 1

                for y in range(0, self.N):
                    for x in range(0, self.N):
                        if (rows[y] or columns[x]) and clear:
                            self.map[y][x] = 0

            size = 0
            for y in range(0, self.N):
                for x in range(0, self.N):
                    if self.map[y][x] > 0:
                        size += 1

            if size == 0:
                self.score += 500

            self.score += placed
            self.score += clearColumns * clearColumns + clearRows * clearRows + (5 * clearRows * clearColumns)
            self.moves += 1

        output = "";
        for i in range(0, len(res)):
            if (i > 0):
                output += " "

            output += str(res[i])

        return output

    def getMoves(self, pieces):
        res = [-1 for i in range(0, 9)]
        tMap = [[0 for i2 in range(0, self.N)] for j2 in range(0, self.N)]

        for y in range(0, self.N):
            for x in range(0, self.N):
                tMap[y][x] = self.map[y][x]

        for i in range(0, len(pieces)):
            p = self.defi[pieces[i]]

            found_move = False
            for y in range(0, self.N):
                for x in range(0, self.N):
                    if not found_move:
                        valid = True
                        for py in range(0, len(p)):
                            for px in range(0, len(p[0])):
                                if valid and (y+py >= self.N or x+px >= self.N or (p[py][px] > 0 and tMap[y+py][x+px] != 0)):
                                    valid = False
                                    break
                        if (valid):
                            for py in range(0, len(p)):
                                for px in range(0, len(p[0])):
                                    if (p[py][px] > 0):
                                        tMap[y+py][x+px] = pieces[i] +1

                            res[i*3 + 0] = i+1
                            res[i*3 + 1] = y+len(p)
                            res[i*3 + 2] = x+1
                            found_move = True
                            break

        return res

    defi = [
        [
            [1],
        ],
        [
            [1],
            [1],
        ],
        [
            [1, 1],
        ],
        [
            [1],
            [1],
            [1],
        ],
        [
            [1, 1, 1],
        ],
        [
            [1],
            [1],
            [1],
            [1],
        ],
        [
            [1, 1, 1, 1],
        ],
        [
            [1],
            [1],
            [1],
            [1],
            [1],
        ],
        [
            [1, 1, 1, 1, 1],
        ],
        [
            [1, 1],
            [1, 1],
        ],
        [
            [1, 1, 1],
            [1, 1, 1],
            [1, 1, 1],
        ],
        [
            [1, 1, 1],
            [0, 0, 1],
            [0, 0, 1],
        ],
        [
            [0, 0, 1],
            [0, 0, 1],
            [1, 1, 1],
        ],
        [
            [1, 0, 0],
            [1, 0, 0],
            [1, 1, 1],
        ],
        [
            [1, 1, 1],
            [1, 0, 0],
            [1, 0, 0],
        ],
        [
            [1, 1],
            [1, 0],
        ],
        [
            [1, 1],
            [0, 1],
        ],
        [
            [0, 1],
            [1, 1],
        ],
        [
            [1, 0],
            [1, 1],
        ],
    ]


class JUNE16:
    def __init__(self):
        self.CHNWGM()

    def CHNWGM(self):
        game = NewGame2()
        while True:
            a = [int(x)-1 for x in input().split()]
            if a[0] < 0 or a[1] < 0 or a[2] < 0:
                return
            print(game.play(a))

            sys.stdout.flush()
            sys.stdin.flush()


def __starting_point():
    JUNE16()

__starting_point()

arr = input().split()
print(-1, -1, -1, -1, -1, -1, -1, -1, -1)


print(-1, -1, -1, -1, -1, -1, -1, -1, -1)


# -*- coding: utf-8 -*-


xyz = [
	[-1, -1],
	[1, 1],
	[2, 9],
	[1, 2],
	[3, 10],
	[1, 4],
	[6, 9],
	[2, 1],
	[8, 10],
	[3, 1],
	[2, 7],
	[5, 6],
	[6, 1],
	[8, 6],
	[7, 1],
	[8, 5],
	[10, 1],
	[10, 3],
	[10, 5],
	[10, 7]
]

dim = [
	[-1, -1],
	[0, 0],
	[1, 0],
	[0, 0],
	[2, 0],
	[0, 0],
	[3, 0],
	[0, 0],
	[4, 0],
	[0, 0],
	[1, 0],
	[2, 0],
	[2, 0],
	[2, 0],
	[2, 0],
	[2, 0],
	[1, 0],
	[1, 0],
	[1, 0],
	[1, 0]
]

A, B, C = list(map(int, input().split()))
print('1', dim[A][0]+1, dim[A][1]+1, '2', 5+dim[B][0]+1, 5+dim[B][1]+1, '3', 5+dim[C][0]+1, dim[C][0]+1)
print('-1 '*9)
# print '2', xyz[C][0], xyz[C][1], '3', xyz[B][0], xyz[B][1], '-1 '*3 


# -*- coding: utf-8 -*-


xyz = [
	[-1, -1],
	[1, 1],
	[2, 9],
	[1, 2],
	[3, 10],
	[1, 4],
	[6, 9],
	[2, 1],
	[8, 10],
	[3, 1],
	[2, 7],
	[5, 6],
	[6, 1],
	[8, 6],
	[7, 1],
	[8, 5],
	[10, 1],
	[10, 3],
	[10, 5],
	[10, 7]
]

dim = [
	[-1, -1],
	[0, 0],
	[1, 0],
	[0, 0],
	[2, 0],
	[0, 0],
	[3, 0],
	[0, 0],
	[4, 0],
	[0, 0],
	[1, 0],
	[2, 0],
	[2, 0],
	[2, 0],
	[2, 0],
	[2, 0],
	[1, 0],
	[1, 0],
	[1, 0],
	[1, 0]
]

A, B, C = list(map(int, input().split()))
print('1', dim[A][0]+1, dim[A][1]+1, '2', 5+dim[B][0], 5+dim[B][1], '-1 '*3)
# print '2', xyz[C][0], xyz[C][1], '3', xyz[B][0], xyz[B][1], '-1 '*3 


# -*- coding: utf-8 -*-


xyz = [
	[-1, -1],
	[1, 1],
	[2, 9],
	[1, 2],
	[3, 10],
	[1, 4],
	[6, 9],
	[2, 1],
	[8, 10],
	[3, 1],
	[2, 7],
	[5, 6],
	[6, 1],
	[8, 6],
	[7, 1],
	[8, 5],
	[10, 1],
	[10, 3],
	[10, 5],
	[10, 7]
]

A, B, C = list(map(int, input().split()))
print('3', xyz[C][0], xyz[C][1], '-1 '*6) 


A = list(map(int, input().split()))
print('-1 '*9)

from sys import stdin,stdout
from itertools import permutations
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def bounded(x,y):
 return 0<=x<=9 and 0<=y<=9
def adjzero(tempGrid,block,x,y):
 ones=0
 for i in range(5):
  for j in range(5):
   if bounded(x+i,y+j) and blocks[block][i][j]:
    if bounded(x+i-1,y+j) and (i==0 or blocks[block][i-1][j]==0 )and tempGrid[x+i-1][y+j]==0: ones+=1
    if bounded(x+i,y+j-1) and (j==0 or blocks[block][i][j-1]==0) and tempGrid[x+i][y+j-1]==0: ones+=1
    if bounded(x+i,y+j+1) and (j==4 or blocks[block][i][j+1]==0) and tempGrid[x+i][y+j+1]==0: ones+=1
    if bounded(x+i+1,y+j) and (i==4 or blocks[block][i+1][j]==0) and tempGrid[x+i+1][y+j]==0: ones+=1
 return ones
def adjnon(tempGrid,block,x,y):
 ones=0
 for i in range(5):
  for j in range(5):
   if bounded(x+i,y+j) and blocks[block][i][j]:
    if bounded(x+i-1,y+j) and (i==0 or blocks[block][i-1][j]==0 )and tempGrid[x+i-1][y+j]: ones+=1
    if bounded(x+i,y+j-1) and (j==0 or blocks[block][i][j-1]==0) and tempGrid[x+i][y+j-1]: ones+=1
    if bounded(x+i,y+j+1) and (j==4 or blocks[block][i][j+1]==0) and tempGrid[x+i][y+j+1]: ones+=1
    if bounded(x+i+1,y+j) and (i==4 or blocks[block][i+1][j]==0) and tempGrid[x+i+1][y+j]: ones+=1
 return ones
def boundary(tempGrid,block,x,y):
 bnd=0
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j] and  (x+i+1==10 or x+i-1==-1): bnd+=1
   if blocks[block][i][j] and(y+j+1==10 or y+j-1==-1): bnd+=1
 return bnd
def points(block,x,y):
 # creatw a local copy
 # place it on grid
 tempGrid=[i[:] for i in grid] 
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    tempGrid[i+x][j+y]=block
 #calculate lines heuristics
 lines=0
 for i in range(10):
  for j in range(10):
   if tempGrid[i][j]==0: break
  else: lines+=1
 for j in range(10):
  for i in range(10):
   if tempGrid[i][j]==0: break
  else: lines+=1
 #caculatw nearby non zeroes
 nearby=adjnon(tempGrid,block,x,y)
 nearholes=adjnon(tempGrid,block,x,y)
 #calculate boundary close points
 bndcls=boundary(tempGrid,block,x,y)
 return 20.0*lines+0.25*nearby+0.1*bndcls
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 horz=[]
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: horz.append(i)
 vertz=[]
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: vertz.append(j)
 for i in horz: clearLine(i,True)
 for i in vertz: clearLine(i,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 pos=[]
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block) : 
    pos.append((points(block,i,j),i,j))
 #print pos
 if pos: return max(pos)
 return (-1,-1,-1)
while True:
 a,b,c=list(map(int,stdin.readline().split()))
 if (a,b,c)==(-1,-1,-1): break
 li=[(a,1),(b,2),(c,3)]
 perms=permutations(li)
 maxp=[]
 maxv=-10
 pos=[]
 for p in perms:
  tempGrid=[i[:] for i in grid]
  t1=findPos(p[0][0])
  if t1!=(-1,-1,-1):
   placeBlock(p[0][0],t1[1],t1[2])
   clearFilledLines()
  t2=findPos(p[1][0])
  if t2!=(-1,-1,-1):
   placeBlock(p[1][0],t2[1],t2[2])
   clearFilledLines()
  t3=findPos(p[2][0])
  if t3!=(-1,-1,-1):
   placeBlock(p[2][0],t3[1],t3[2])
   clearFilledLines()
  if (t1[0]+t2[0]+t3[0])>maxv:
   maxv=(t1[0]+t2[0]+t3[0])
   pos=[t1[1:],t2[1:],t3[1:]]
   maxp=p
  grid=tempGrid
 outstr=[]
 count=0
 for pi in range(len(maxp)):
  if pos[pi][0]!=-1:
    i=maxp[pi]
    x=pos[pi][0]
    y=pos[pi][1]
    #print x,y
    placeBlock(i[0],x,y)
    clearFilledLines()
    #printGrid()
    outstr.extend([i[1],x+1+leftBelow[i[0]][0],y+1])
    count+=1
 for i in range(3-count):
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()
 

from sys import stdin,stdout
from itertools import permutations
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def bounded(x,y):
 return 0<=x<=9 and 0<=y<=9
def adjzero(tempGrid,block,x,y):
 ones=0
 for i in range(5):
  for j in range(5):
   if bounded(x+i,y+j) and blocks[block][i][j]:
    if bounded(x+i-1,y+j) and (i==0 or blocks[block][i-1][j]==0 )and tempGrid[x+i-1][y+j]==0: ones+=1
    if bounded(x+i,y+j-1) and (j==0 or blocks[block][i][j-1]==0) and tempGrid[x+i][y+j-1]==0: ones+=1
    if bounded(x+i,y+j+1) and (j==4 or blocks[block][i][j+1]==0) and tempGrid[x+i][y+j+1]==0: ones+=1
    if bounded(x+i+1,y+j) and (i==4 or blocks[block][i+1][j]==0) and tempGrid[x+i+1][y+j]==0: ones+=1
 return ones
def adjnon(tempGrid,block,x,y):
 ones=0
 for i in range(5):
  for j in range(5):
   if bounded(x+i,y+j) and blocks[block][i][j]:
    if bounded(x+i-1,y+j) and (i==0 or blocks[block][i-1][j]==0 )and tempGrid[x+i-1][y+j]: ones+=1
    if bounded(x+i,y+j-1) and (j==0 or blocks[block][i][j-1]==0) and tempGrid[x+i][y+j-1]: ones+=1
    if bounded(x+i,y+j+1) and (j==4 or blocks[block][i][j+1]==0) and tempGrid[x+i][y+j+1]: ones+=1
    if bounded(x+i+1,y+j) and (i==4 or blocks[block][i+1][j]==0) and tempGrid[x+i+1][y+j]: ones+=1
 return ones
def boundary(tempGrid,block,x,y):
 bnd=0
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j] and  (x+i+1==10 or x+i-1==-1): bnd+=1
   if blocks[block][i][j] and(y+j+1==10 or y+j-1==-1): bnd+=1
 return bnd
def points(block,x,y):
 # creatw a local copy
 # place it on grid
 tempGrid=[i[:] for i in grid] 
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    tempGrid[i+x][j+y]=block
 #calculate lines heuristics
 lines=0
 for i in range(10):
  for j in range(10):
   if tempGrid[i][j]==0: break
  else: lines+=1
 for j in range(10):
  for i in range(10):
   if tempGrid[i][j]==0: break
  else: lines+=1
 #caculatw nearby non zeroes
 nearby=adjnon(tempGrid,block,x,y)
 nearholes=adjnon(tempGrid,block,x,y)
 #calculate boundary close points
 bndcls=boundary(tempGrid,block,x,y)
 return 20.0*lines+0.25*nearby+0.5*bndcls
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 horz=[]
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: horz.append(i)
 vertz=[]
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: vertz.append(j)
 for i in horz: clearLine(i,True)
 for i in vertz: clearLine(i,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 pos=[]
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block) : 
    pos.append((points(block,i,j),i,j))
 #print pos
 if pos: return max(pos)
 return (-1,-1,-1)
while True:
 a,b,c=list(map(int,stdin.readline().split()))
 if (a,b,c)==(-1,-1,-1): break
 li=[(a,1),(b,2),(c,3)]
 perms=permutations(li)
 maxp=[]
 maxv=-10
 pos=[]
 for p in perms:
  tempGrid=[i[:] for i in grid]
  t1=findPos(p[0][0])
  if t1!=(-1,-1,-1):
   placeBlock(p[0][0],t1[1],t1[2])
   clearFilledLines()
  t2=findPos(p[1][0])
  if t2!=(-1,-1,-1):
   placeBlock(p[1][0],t2[1],t2[2])
   clearFilledLines()
  t3=findPos(p[2][0])
  if t3!=(-1,-1,-1):
   placeBlock(p[2][0],t3[1],t3[2])
   clearFilledLines()
  if (t1[0]+t2[0]+t3[0])>maxv:
   maxv=(t1[0]+t2[0]+t3[0])
   pos=[t1[1:],t2[1:],t3[1:]]
   maxp=p
  grid=tempGrid
 outstr=[]
 count=0
 for pi in range(len(maxp)):
  if pos[pi][0]!=-1:
    i=maxp[pi]
    x=pos[pi][0]
    y=pos[pi][1]
    #print x,y
    placeBlock(i[0],x,y)
    clearFilledLines()
    #printGrid()
    outstr.extend([i[1],x+1+leftBelow[i[0]][0],y+1])
    count+=1
 for i in range(3-count):
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()
 

from sys import stdin,stdout,exit
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 horz=[]
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: horz.append(i)
 vertz=[]
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: vertz.append(j)
 for i in horz: clearLine(i,True)
 for i in vertz: clearLine(i,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
while True:
 a,b,c=list(map(int,stdin.readline().split()))
 if (a,b,c)==(-1,-1,-1): break
 li=[(a,1),(b,2),(c,3)]
 outstr=[]
 count=0
 while li:
  for i in li:
   x,y=findPos(i[0])
   if x!=-1:
    placeBlock(i[0],x,y)
    clearFilledLines()
    #printGrid()
    li.remove(i)
    outstr.extend([i[1],x+1+leftBelow[i[0]][0],y+1])
    count+=1
    break
  else: break
 for i in range(3-count):
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()
 

from sys import stdin,stdout,exit
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 horz=[]
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: horz.append(i)
 vertz=[]
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: vertz.append(j)
 for i in horz: clearLine(i,True)
 for i in vertz: clearLine(i,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
while True:
 a,b,c=list(map(int,stdin.readline().split()))
# print pattern[a],pattern[b],pattern[c]
 if (a,b,c)==(-1,-1,-1): break
 outstr=[]
 x,y=findPos(a)
 count=0
 if x==-1:
  count+=1
 else:
  outstr.extend([1,x+1+leftBelow[a][0],y+1])
  placeBlock(a,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(b)
 if x==-1: count+=1
 else:
  outstr.extend([2,x+1+leftBelow[b][0],y+1])
  placeBlock(b,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(c)
 if x==-1: count+=1
 else:
  outstr.extend([3,x+1+leftBelow[c][0],y+1])
  placeBlock(c,x,y)
  clearFilledLines()
  #printGrid()
 #printGrid()
 for i in range(count): 
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()

from sys import stdin,stdout,exit
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: clearLine(i,True)
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: clearLine(j,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
cnt=15
while True:
 a,b,c=list(map(int,stdin.readline().split()))
# print pattern[a],pattern[b],pattern[c]
 if (a,b,c)==(-1,-1,-1): break
 cnt-=1
 if not cnt:
  print("-1 -1 -1 -1 -1 -1 -1 -1 -1")
  stdout.flush()
  continue
 outstr=[]
 x,y=findPos(a)
 count=0
 if x==-1:
  count+=1
 else:
  outstr.extend([1,x+1+leftBelow[a][0],y+1])
  placeBlock(a,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(b)
 if x==-1: count+=1
 else:
  outstr.extend([2,x+1+leftBelow[b][0],y+1])
  placeBlock(b,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(c)
 if x==-1: count+=1
 else:
  outstr.extend([3,x+1+leftBelow[c][0],y+1])
  placeBlock(c,x,y)
  clearFilledLines()
  #printGrid()
# printGrid()
 for i in range(count): 
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()

from sys import stdin,stdout,exit
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: clearLine(i,True)
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: clearLine(j,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
cnt=10
while True:
 a,b,c=list(map(int,stdin.readline().split()))
# print pattern[a],pattern[b],pattern[c]
 if (a,b,c)==(-1,-1,-1): break
 cnt-=1
 if not cnt:
  print("-1 -1 -1 -1 -1 -1 -1 -1 -1")
  stdout.flush()
  continue
 outstr=[]
 x,y=findPos(a)
 count=0
 if x==-1:
  count+=1
 else:
  outstr.extend([1,x+1+leftBelow[a][0],y+1])
  placeBlock(a,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(b)
 if x==-1: count+=1
 else:
  outstr.extend([2,x+1+leftBelow[b][0],y+1])
  placeBlock(b,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(c)
 if x==-1: count+=1
 else:
  outstr.extend([3,x+1+leftBelow[c][0],y+1])
  placeBlock(c,x,y)
  clearFilledLines()
  #printGrid()
# printGrid()
 for i in range(count): 
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()

from sys import stdin,stdout,exit
from random import random
def printBS(li):
 s=[str(i) for i in li]
 print(" ".join(s))
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
pattern={1: "dot",2: "vert 2 line",3: "hor 2 line", 4: "vert 3",5: "hor 3",6:"vert 4",7: "hor 4", 8: "vert 5",9: "hor 5",10: "2*2",11:"3*3",12: " 3T3R", 13: "3R3B",14: "3L3B",15:"3L3T",16:"2L2T",17:"2R2T",18: "2R2B",19:"2L2B"}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=block
def clearFilledLines():
 #check horizontal
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: clearLine(i,True)
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: clearLine(j,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print("%02d"%grid[i][j], end=' ')
  print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
cnt=5
while True:
 a,b,c=list(map(int,stdin.readline().split()))
# print pattern[a],pattern[b],pattern[c]
 if (a,b,c)==(-1,-1,-1): break
 cnt-=1
 if not cnt:
  print("-1 -1 -1 -1 -1 -1 -1 -1 -1")
  stdout.flush()
  continue
 outstr=[]
 x,y=findPos(a)
 count=0
 if x==-1:
  count+=1
 else:
  outstr.extend([1,x+1+leftBelow[a][0],y+1])
  placeBlock(a,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(b)
 if x==-1: count+=1
 else:
  outstr.extend([2,x+1+leftBelow[b][0],y+1])
  placeBlock(b,x,y)
  clearFilledLines()
  #printGrid()
 x,y=findPos(c)
 if x==-1: count+=1
 else:
  outstr.extend([3,x+1+leftBelow[c][0],y+1])
  placeBlock(c,x,y)
  clearFilledLines()
  #printGrid()
# printGrid()
 for i in range(count): 
  outstr.extend([-1,-1,-1])
 printBS(outstr)
 stdout.flush()

from sys import stdin,stdout
from random import random
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=1
def clearFilledLines():
 #check horizontal
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: clearLine(i,True)
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: clearLine(j,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print(grid[i][j], end=' ')
  print() 
 print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]==1:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]==1: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
resCount=0
a,b,c=list(map(int,stdin.readline().split()))
while (a,b,c)!=(-1,-1,-1):
 outstr=[]
 x,y=findPos(a)
 count=0
 if x==-1:
  count+=1
 else:
  outstr.extend([1,x+1+leftBelow[a][0],y+1])
  placeBlock(a,x,y)
  clearFilledLines()
 #printGrid()
 x,y=findPos(b)
 if x==-1: count+=1
 else:
  outstr.extend([2,x+1+leftBelow[b][0],y+1])
  placeBlock(b,x,y)
  clearFilledLines()
 #printGrid()
 x,y=findPos(c)
 if x==-1: count+=1
 else:
  outstr.extend([3,x+1+leftBelow[c][0],y+1])
  placeBlock(c,x,y)
  clearFilledLines()
 #printGrid()
 for i in range(count): 
  outstr.extend([-1,-1,-1])
 stdout.write(" ".join([str(i) for i in outstr])+"\n")
 stdout.flush()
 resCount+=1
 a,b,c=list(map(int,stdin.readline().split()))
 if resCount>10:
  print("-1 -1 -1 -1 -1 -1 -1 -1 -1")
  stdout.flush()
  a=stdin.readline()
  break

from sys import stdin,stdout
from random import random
#grid defined as array 10x10 of 0's and 1's 1 means occupied
grid=[[0]*10 for i in range(10)]
blocks=({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]] 
        ,2:[[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,3:[[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]] 
        ,4:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 5:[[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]] 
       , 6:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0]] 
       , 7:[[1,1,1,1,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  8:[[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] 
     ,   9:[[1,1,1,1,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 10:[[1,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 11:[[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 12:[[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 13:[[0,0,1,0,0],[0,0,1,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
      ,  14:[[1,0,0,0,0],[1,0,0,0,0],[1,1,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 15:[[1,1,1,0,0],[1,0,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
       , 16:[[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]  
       , 17:[[1,1,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
      ,  18:[[0,1,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] 
        ,19:[[1,0,0,0,0],[1,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]})
leftBelow={1:(0,0),2:(1,0),3:(0,0),4:(2,0),5:(0,0),6:(3,0),7:(0,0),8:(4,0),9:(0,0),10:(1,0),11:(2,0),12:(2,0),13:(2,0),14:(2,0),15:(2,0),16:(1,0),17:(1,0),18:(1,0),19:(1,0)}
def clearLine(lineNo,isRow):
 if isRow:
  for i in range(10):
   grid[lineNo][i]=0
 else:
  for i in range(10):
   grid[i][lineNo]=0
def placeBlock(block,x,y):
 for i in range(min(5,10-x)):
  for j in range(min(5,10-y)):
   if blocks[block][i][j]==1:
    grid[i+x][j+y]=1
def clearFilledLines():
 #check horizontal
 for i in range(10):
  for j in range(10):
   if grid[i][j]==0: break
  else: clearLine(i,True)
 #check vertical
 for j in range(10):
  for i in range(10):
   if grid[i][j]==0: break
  else: clearLine(j,False)
def printGrid():
 for i in range(10):
  for j in range(10):
   print(grid[i][j], end=' ')
  print() 
 print()
def checkPos(x,y,block):
 for i in range(5):
  for j in range(5):
   if blocks[block][i][j]==1:
    if x+i>9 or y+j>9: return False
    if grid[i+x][j+y]==1: return False
 return True
def findPos(block):
 for i in range(10):
  for j in range(10):
   if checkPos(i,j,block): return i,j
 return -1,-1
resCount=0
a,b,c=list(map(int,stdin.readline().split()))
while (a,b,c)!=(-1,-1,-1):
 outstr=[]
 x,y=findPos(a)
 count=0
 if x==-1:
  count+=1
 else:
  outstr.extend([1,x+1+leftBelow[a][0],y+1])
  placeBlock(a,x,y)
  clearFilledLines()
 #printGrid()
 x,y=findPos(b)
 if x==-1: count+=1
 else:
  outstr.extend([2,x+1+leftBelow[b][0],y+1])
  placeBlock(b,x,y)
  clearFilledLines()
 #printGrid()
 x,y=findPos(c)
 if x==-1: count+=1
 else:
  outstr.extend([3,x+1+leftBelow[c][0],y+1])
  placeBlock(c,x,y)
  clearFilledLines()
 #printGrid()
 for i in range(count): 
  outstr.extend([-1,-1,-1])
 stdout.write(" ".join([str(i) for i in outstr])+"\n")
 stdout.flush()
 resCount+=1
 a,b,c=list(map(int,stdin.readline().split()))
 if resCount>5:
  print("-1 -1 -1 -1 -1 -1 -1 -1 -1")
  stdout.flush()
  a=stdin.readline()
  break

import sys
mp=[[0 for i in range(10)] for j in range(10)]
an=[0,0]
x=[]
y=[]
def smx(index):
    if index==1:
        y=[0]
    elif index==2:
        y=[0,1]
    elif index==3:
        y=[0,0]
    elif index==4:
        y=[0,1,2]
    elif index==5:
        y=[0,0,0]
    elif index==6:
        y=[0,1,2,3]
    elif index==7:
        y=[0,0,0,0]
    elif index==8:
        y=[0,1,2,3,4]
    elif index==9:
        y=[0,0,0,0,0]
    elif index==10:
        y=[0,1,0,1]
    elif index==11:
        y=[0,1,2,0,1,2,0,1,2]
    elif index==12:
        y=[0,0,0,1,2]
    elif index==13:
        y=[2,2,0,1,2]
    elif index==14:
        y=[0,1,2,2,2]
    elif index==15:
        y=[0,1,2,0,0]
    elif index==16:
        y=[0,1,0]
    elif index==17:
        y=[0,0,1]
    elif index==18:
        y=[1,0,1]
    elif index==19:
        y=[0,1,1]
    return max(y)
def chk():
    for i in range(10):
        if sum(mp[i])==10:
            for j in range(10):
                mp[i][j]=0
    for j in range(10):
        flag=1
        for i in range(10):
            if mp[i][j]==0:
                flag=0
                break
        if flag==1:
            for i in range(10):
                mp[i][j]=0
def fil(y,x):
    for i1 in range(len(x)):
        if an[0]+x[i1]<10 and an[1]+y[i1]<10:
            mp[an[0]+x[i1]][an[1]+y[i1]]=1
    #chk()
def ind(y,x):
    for i in range(10):
        for j in range(10):
            flag=1
            for i1 in range(len(x)):
                if i+x[i1]<10 and j+y[i1]<10 and mp[i+x[i1]][j+y[i1]]!=0:
                    flag=-1
                    break
                if i+x[i1]>=10 or j+y[i1]>=10:
                    flag=-1
                    break
            if flag==1:
                an[0]=i
                an[1]=j
                return True
    return False
def find(index):
    if index==1:
        x=[0]
        y=[0]
    elif index==2:
        x=[0,0]
        y=[0,1]
    elif index==3:
        x=[0,1]
        y=[0,0]
    elif index==4:
        x=[0,0,0]
        y=[0,1,2]
    elif index==5:
        x=[0,1,2]
        y=[0,0,0]
    elif index==6:
        x=[0,0,0,0]
        y=[0,1,2,3]
    elif index==7:
        x=[0,1,2,3]
        y=[0,0,0,0]
    elif index==8:
        x=[0,0,0,0,0]
        y=[0,1,2,3,4]
    elif index==9:
        x=[0,1,2,3,4]
        y=[0,0,0,0,0]
    elif index==10:
        x=[0,0,1,1]
        y=[0,1,0,1]
    elif index==11:
        x=[0,0,0,1,1,1,2,2,2]
        y=[0,1,2,0,1,2,0,1,2]
    elif index==12:
        x=[0,1,2,2,2]
        y=[0,0,0,1,2]
    elif index==13:
        x=[0,1,2,2,2]
        y=[2,2,0,1,2]
    elif index==14:
        x=[0,0,0,1,2]
        y=[0,1,2,2,2]
    elif index==15:
        x=[0,0,0,1,2]
        y=[0,1,2,0,0]
    elif index==16:
        x=[0,0,1]
        y=[0,1,0]
    elif index==17:
        x=[0,1,1]
        y=[0,0,1]
    elif index==18:
        x=[0,1,1]
        y=[1,0,1]
    elif index==19:
        x=[0,0,1]
        y=[0,1,1]
    if ind(x,y):
        fil(x,y)
        return True
    return False
a,b,c=list(map(int,input().split()))
while(a!=-1):
    ans=""
    flag=0
    if find(a):
       ans+="1 "+ str(an[0]+1+smx(a))+" "+str(an[1]+1)+" "
    else:
        flag+=1
    if find(b):
       ans+="2 "+ str(an[0]+1+smx(b))+" "+str(an[1]+1)+" "
    else:
        flag+=1
    if find(c):
       ans+="3 "+ str(an[0]+1+smx(c))+" "+str(an[1]+1)+" "
    else:
        flag+=1
    while(flag>0):
        ans+="-1 -1 -1 "
        flag-=1
    print(ans)
    sys.stdout.flush()
    a,b,c=list(map(int,input().split()))


import sys
a,b,c=list(map(int,input().split()))
rr=[0,0,5,5]
cc=[0,5,0,5]
cur=0
while(a!=-1):
    ans=""
    for i in range(3):
        if cur<4:
            ans+=str(i+1)+" "+str(rr[cur]+5)+" "+str(cc[cur]+1)+" "
        else:
            ans+="-1"+" -1"+" -1"+" "
        cur+=1
    print(ans)
    sys.stdout.flush()
    a,b,c=list(map(int,input().split()))