object Main extends App {

  override def main(args: Array[String]) {
    val milleniumDay = new Date(1000, 1, 1).toInt
    val n = io.StdIn.readLine.toInt
    (1 to n).map(_ => io.StdIn.readLine.split(' ')).map(spl => new Date(spl(0).toInt, spl(1).toInt, spl(2).toInt).toInt)
      .foreach(dayFrom1 => println(milleniumDay - dayFrom1))
  }

  case class Date(Y: Int, M: Int, D: Int) {
    val daysOfMonthBig = 20
    val daysOfMonthSmall = 19
    val monthToDayNormal: Int => Int = m => (m - 1) / 2 * daysOfMonthSmall + m / 2 * daysOfMonthBig
    val monthToDay3ish: Int => Int = m => (m - 1) * daysOfMonthBig
    val monthToDay: Int => Int => Int = y => if (y % 3 == 0) monthToDay3ish else monthToDayNormal
    val daysOfYearNormal = monthToDayNormal(11)
    val daysOfYear3ish = monthToDay3ish(11)
    val daysOf3Years = daysOfYearNormal + daysOfYearNormal + daysOfYear3ish
    val yearToDay: Int => Int = y => (y - 1) / 3 * daysOf3Years + (y - 1) % 3 * daysOfYearNormal
    val toInt = yearToDay(Y) + monthToDay(Y)(M) + D
  }
}