### subroutines

def doy(y, m, d)
  (y % 3 == 0) ?
    (m - 1) * 20 + d :
    (1...m).map{|m0| (m0 % 2 == 1) ? 20 : 19}.inject(0){|s, md| s + md} + d
end

def yd(y)
  (y % 3 == 0) ? 20 * 10 : (20 + 19) * 5
end

### main

n = gets.to_i

n.times do
  yi, mi, di = gets.split.map(&:to_i)
  #p [yi, mi, di]

  puts (yi...1000).map{|y0| yd(y0)}.inject(:+) - doy(yi, mi, di) + 1
end