import java.lang.Math.*

fun main(args:Array<String>):Unit {
    val pole = angleToPoint(.0, 43.2).toVector()
    val angleVelocity = (1 + 1 / 365.24) * PI * 2
    repeat(readLine()!!.trim().toInt()) {
        val (dateStr, timeStr) = readLine()!!.trim().split(' ')
        val date = Date(dateStr)
        val time = Time(timeStr)
        val constellation = Array(readLine()!!.trim().toInt()) {
            val (name, starSize) = readLine()!!.trim().split(' ')
            Constellation(name, Array(starSize.toInt()) {
                val (azimuth, elevation) = readLine()!!.trim().split(' ').map(String::toDouble)
                angleToPoint(azimuth, elevation)
            }.asIterable())
        }
        val q = Quaternion.screwLeft(pole, angleVelocity * (date.dayFromNewYear + time.time))
        println(
                constellation.filter{
                    it.rotate(q).isCanSee()
                }.joinToString("\n"){it.name}
        )
    }
}
data class Date(val month:Int, val day:Int){
    constructor(date:String):this(date.split('/').first().toInt(), date.split('/').last().toInt())
    val dayFromNewYear:Int
        get() = monthes.take(month).sum() + day - 1
    companion object {
        private val monthes:Iterable<Int> = listOf(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    }
}
data class Time(val hour:Int, val minute:Int){
    constructor(time:String):this(time.split(':').first().toInt(), time.split(':').last().toInt())
    val time:Double
        get() = (hour + minute / 60e0) / 24
}
class Constellation(val name:String, private val mStars:Iterable<Point>){
    fun rotate(quaternion: Quaternion):Constellation {
        return Constellation(name, mStars.map{(quaternion * it.toQuaternion() * conjugate(quaternion)).toPoint()})
    }
    fun isCanSee():Boolean = mStars.all{it.z > 0}
}
fun angleToPoint(azimuth:Double, elevation:Double):Point {
    val azimuthQ = Quaternion.screwLeft(Vector(0e0, 0e0, 1e0), azimuth * PI / 180)
    val elevationQ = Quaternion.screwLeft(Vector(0e0, 1e0, 0e0), elevation * PI / 180)
    return (azimuthQ * elevationQ * Vector(1e0, 0e0, 0e0).toQuaternion() * conjugate(elevationQ) * conjugate(azimuthQ)).toPoint()
}
data class Point(val x:Double, val y:Double, val z:Double){
    constructor(x:Int, y:Int, z:Int):this(x.toDouble(), y.toDouble(), z.toDouble())
}
fun Quaternion.toPoint():Point{
    return Point(this.i, this.j, this.k)
}
fun Point.toQuaternion():Quaternion{
    return Quaternion(0e0, this.x, this.y, this.z)
}
data class Vector(val x:Double, val y:Double, val z:Double){
    val length:Double = sqrt(x * x + y * y + z * z)
    fun map(transformer:(Double) -> Double):Vector = Vector(transformer(x), transformer(y), transformer(z))
}
operator fun Vector.times(other:Double):Vector = this.map{it * other}
operator fun Vector.div(other:Double):Vector = this.map{it / other}
fun Vector.toQuaternion():Quaternion {
    return Quaternion(0e0, this.x, this.y, this.z)
}
fun Point.toVector():Vector{
    return Vector(this.x, this.y, this.z)
}
data class Quaternion(val real:Double, val i:Double, val j:Double, val k:Double){
    operator fun plus(that:Quaternion):Quaternion = Quaternion(real + that.real, i + that.i, j + that.j, k + that.k)
    operator fun times(that:Quaternion):Quaternion {
        return timesR(that.real) + timesI(that.i) + timesJ(that.j) + timesK(that.k)
    }
    private fun timesI(value:Double):Quaternion = Quaternion(-i * value, real * value, -k * value, j * value)
    private fun timesJ(value:Double):Quaternion = Quaternion(-j * value, k * value, real * value, -i * value)
    private fun timesK(value:Double):Quaternion = Quaternion(-k * value, -j * value, i * value, real * value)
    private fun timesR(value:Double):Quaternion = Quaternion(real * value, i * value, j * value, k * value)
    companion object {
        fun screwLeft(axis:Vector, radian:Double):Quaternion {
            val normalizedAxis = axis / axis.length * sin(radian / 2)
            return Quaternion(cos(radian / 2), normalizedAxis.x, normalizedAxis.y, normalizedAxis.z)
        }
    }
}
fun conjugate(quaternion: Quaternion):Quaternion {
    return Quaternion(quaternion.real, -quaternion.i, -quaternion.j, -quaternion.k)
}
