import java.lang.Math.*

fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    repeat(n){
        val (r, t) = readLine()!!.trim().split(' ').map(String::toInt)
        println(measurePoint(r, t).sorted().joinToString(" "))
    }
}
fun measurePoint(distance:Int, angle:Int):Iterable<Int> {
    return (if (distance % 100 == 0)
        listOf(distance / 100)
    else
        listOf(distance / 100, (distance + 100) / 100)).flatMap{d ->
        (if (angle % 30 == 0)
            listOf(angle / 30)
        else
            listOf(angle / 30, (angle + 30) / 30)).map{it * 5 + d}
    }
}
