n = gets.chomp.to_i
yday = Array.new(1000, 195)
yday[0] = 0
(1..999).select{|i| i % 3 == 0}.each do |i|
  yday[i] += 5
end

(2..999).each do |i|
  yday[i] += yday[i-1]
end

n.times do
  y, m, d = gets.chomp.split(" ").map(&:to_i)
  bday = yday[y-1]
  if y % 3 == 0 then
    bday += 20 * (m - 1)
    bday += d
  else
    (1...m).each do |i|
      if i.odd?
        bday += 20
      else
        bday += 19
      end
    end
    bday += d
  end
  puts yday[999] - bday + 1
end