private fun readInts() = readLine()!!.split(" ").map(String::toInt)

fun main(args: Array<out String>) {
    val (n) = readInts()
    val ymd = (0 until n).map { readInts() }

    ymd.forEach { (year, month, day) -> println(calcDays(year, month, day)) }
}

private fun calcDays(startYear: Int, startMonth: Int, startDay: Int): Int {
    if (startYear >= 1000) return 0

    return (1..10)
        .asSequence()
        .drop(startMonth - 1)
        .map { month ->
            if (startYear % 3 != 0) {
                if (month % 2 == 0) 19 else 20
            } else {
                20
            }
        }
        .sum()
        .minus(startDay - 1)
        .plus(calcDays(startYear + 1, 1, 1))
}
