gets.to_i.times do
  y,m,d = gets.split.map(&:to_i)
  res = 0
  while y < 1000
    res, d = res + 1, d + 1
    md = (y % 3 == 0 || m % 2 == 1) ? 20 : 19
    d, m = 1, m + 1 if d > md
    m, y = 1, y + 1 if m > 10
  end
  puts res
end