main = interact $ unlines . map (show . millennium . map read . words) . tail . lines

millennium :: [Int] -> Int
millennium [y,m,d] = day 1000 1 1 - day y m d

day y m d = (y-1) * 195 + (m-1) * 20 + d + diff_y - diff_m
 where
  diff_y = div (y-1) 3 * 5
  diff_m = if mod y 3 /= 0 then div (m-1) 2 else 0