
object Main extends App {

  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val n = readLine.trim.toInt
    val dayToMillennium = Date(1000, 1, 1).dayFromBegin
    for (_ ← 0 until n){
      val Array(y, m, d) = readLine.trim.split(' ').map(_.toInt)
      println(dayToMillennium - Date(y, m, d).dayFromBegin)
    }
  }
  object Date{
    private val sum3YearsDay = 590
    private val sumNormalYearsDay = 195
  }
  case class Date(year: Int, month: Int, day: Int) {
    def dayFromBegin: Int = {
      dayFromBeginToYearsDay + dayFromYearsDayToMonthBegin + dayFromMonthBegin
    }
    private def dayFromBeginToYearsDay: Int = {
      (year - 1) / 3 * Date.sum3YearsDay + (year - 1) % 3 * Date.sumNormalYearsDay
    }
    private def dayFromYearsDayToMonthBegin: Int = {
      if (year % 3 == 0) (month - 1) * 20
      else (month - 1) * 20 - (month - 1) / 2
    }
    private def dayFromMonthBegin: Int = {
      day
    }
  }
}

