# coding: utf-8
# ?????°
B = 20
S = 19
# ?????´???????????\??°?????????
normal_months =  [B,S,B,S,B,S,B,S,B,S]
special_months = [B,B,B,B,B,B,B,B,B,B]
# ?????´?????\??°
normal_dates = 0
normal_months.each do |months|
  normal_dates += months
end
special_dates = 0
special_months.each do |months|
  special_dates += months
end

# ??????????????????
line = gets
# ???????????¨?????????
while line = gets do
  # ????????§????????£???????????????????????????????????????
  year,month,date = line.split
  year = year.to_i
  month = month.to_i
  date = date.to_i
  result = 0
  if year != 1000
    months = []
    if year % 3 != 0
      months = normal_months
    else
      months = special_months
    end
    # ?????¨?????\???????????????????????§?????\???????¶????
    result += months[month-1] - date
    month += 1
    # ?????¨??????-??´????????§???????????\??°????¶????
    while month != 11
      result += months[month-1]
      month += 1
    end
  end
  year += 1
  while year != 1000 do
    if year % 3 != 0
      result += normal_dates
    else
      result += special_dates
    end
    year += 1
  end
  result += 1
  puts result
end