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