n_drop, cloth = int(input()), [[int(i) for i in input().split()] for _ in range(10)]
n_stain = sum(sum(i) for i in cloth)
n = (n_stain - 5 * n_drop) // 4

drops_candidate = []
dl = 0
while 2 * dl <= n:
    dm = n - 2 * dl
    ds = n_drop - dm - dl
    if ds >= 0:
        drops_candidate.append([ds, dm, dl])
    dl += 1

sdxy = ((0, 0), (-1, 0), (1, 0), (0, -1), (0, 1))
mdxy = sdxy + ((-1, -1), (-1, 1), (1, -1), (1, 1))
ldxy = mdxy + ((-2, 0), (2, 0), (0, -2), (0, 2))
dxys = (sdxy, mdxy, ldxy)


def remove(cloth, x, y, drop_size):
    if drop_size == 2 and (not 1 < x < 8 or not 1 < y < 8):
        return False

    for dxy in dxys[drop_size]:
        (dx, dy) = dxy
        if cloth[y + dy][x + dx]:
            cloth[y + dy][x + dx] -= 1
        else:
            return False
    return True


def find(cloth, drops, history):
    for d in range(3):
        if not drops[d]:
            continue
        (start, stop) = (1, 9) if d < 2 else (2, 8)
        for y in range(start, stop):
            for x in range(start, stop):
                for dxy in dxys[d]:
                    (dx, dy) = dxy
                    if not cloth[y + dy][x + dx]:
                        break
                else:
                    new_cloth, new_drops, new_history = [r[:] for r in cloth], drops[:], history[:]
                    for dxy in dxys[d]:
                        (dx, dy) = dxy
                        new_cloth[y + dy][x + dx] -= 1

                    new_drops[d] -= 1
                    new_history.append((x, y, d + 1))
                    if sum(new_drops):
                        result = find(new_cloth, new_drops, new_history)
                        if result:
                            return result
                    else:
                        return new_history
    return False


for drops in drops_candidate:
    history = find(cloth, drops, [])
    if history != False:
        for h in history:
            print(*h)
        break