fun main(args:Array<String>):Unit {
        val dropCount = readLine()!!.trim().toInt()
        val cloth = Array(10){readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
        var drops = search(cloth, dropCount)!!
        while (drops is ImmutableList.Cons){
            println("${drops.head.center.x} ${drops.head.center.y} ${when(drops.head){
                is Drop.Small -> 1
                is Drop.Medium -> 2
                is Drop.Large -> 3
            }}")
            drops = drops.tail
        }
}
fun search(cloth:Array<IntArray>, dropCount:Int):ImmutableList<Drop>?{
    if (dropCount == 0) {
        return if (cloth.all{it.all{it == 0}}) ImmutableList.Nil
        else null
    }
    val point = (0 until cloth.size).flatMap{y -> (0 until cloth.size).map{Point(it, y)}}.find{cloth[it.y][it.x] != 0}
    return when(point){
        null -> null
        else -> {
            drop(point).filter{it.dropArea().all{it.x in 0 until cloth.size && it.y in 0 until cloth.size && cloth[it.y][it.x] > 0}}.forEach {
                it.dropArea().forEach { cloth[it.y][it.x]-- }
                val tail = search(cloth, dropCount - 1)
                when(tail){
                    null -> {
                        it.dropArea().forEach { cloth[it.y][it.x]++ }
                    }
                    else -> return ImmutableList.Cons(it, tail)
                }
            }
            return null
        }
    }
}
fun drop(point:Point):Iterable<Drop>{
    return listOf(Drop.Small(point + Point(0, 1)), Drop.Medium(point + Point(1, 1)), Drop.Large(point + Point(0, 2)))
}
data class Point(val x:Int, val y:Int){
    operator fun plus(that:Point):Point = Point(x + that.x, y + that.y)
}
sealed class Drop(val center:Point){
    protected abstract val relationalDropArea:Iterable<Point>
    fun dropArea():Iterable<Point> = relationalDropArea
    class Small(center:Point):Drop(center){
        override val relationalDropArea: Iterable<Point> = listOf(Point(0, -1), Point(0, 1), Point(-1, 0), Point(1, 0), Point(0, 0)).map{it + center}
    }
    class Medium(center:Point):Drop(center){
        override val relationalDropArea: Iterable<Point> = (-1 .. 1).flatMap{x -> (-1..1).map{Point(x, it)}}.map{it + center}
    }
    class Large(center:Point):Drop(center){
        override val relationalDropArea: Iterable<Point> = (listOf(Point(2, 0), Point(-2, 0), Point(0, 2), Point(0, -2)) + (-1 .. 1).flatMap { x -> (-1 .. 1).map{Point(x, it)} }).map{it + center}
    }
}
sealed class ImmutableList<out T>{
    object Nil:ImmutableList<Nothing>()
    data class Cons<out T>(val head:T, val tail:ImmutableList<T>):ImmutableList<T>()
}
