object Main {
  def count_days(years: Int, months: Int, days: Int): Int = {
    val monthsToDays = {
      val m = months - 1
      if (years % 3 == 0) m * 20
      else (m - m / 2) * 20 + (m / 2) * 19
    }
    val yearsToDays = { val y = years - 1; (y - y / 3) * 195 + (y / 3) * 200 }
    666 * 195 + 333 * 200 - yearsToDays - monthsToDays - days + 1
  }
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextInt
    for(_ <- 1 to n) {
      var y, m, d = sc.nextInt
      println(count_days(y, m, d))
    }
  }
}