n = gets.to_i
n.times{
    y, m, d = gets.chomp.split.map(&:to_i)
    days = 0
    1.upto(y - 1){|year| days += (year % 3 == 0) ? 200 : 195}
    1.upto(m - 1){|month| days += (month % 2 == 0) ? (y % 3 == 0 ? 20 : 19) : 20}
    1.upto(d){|day| days += 1}
    puts 196471 - days
}

