A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a _big month_. A common year shall start with a big month, followed by _small months_ and big months one after another. Therefore the first month is a big month, the second month is a small month, the third a big month, ..., and the 10th and last month a small one. A big month consists of 20 days and a small month consists of 19 days. However years which are multiples of three, that are year 3, year 6, year 9, and so on, shall consist of 10 big months and no small month."  Many years have passed since the calendar started to be used. For celebration of the millennium day (the year 1000, month 1, day 1), a royal lottery is going to be organized to send gifts to those who have lived as many days as the number chosen by the lottery. Write a program that helps people calculate the number of days since their birthdate to the millennium day.
n = int(input())
for _ in range(n):
    (y, m, d) = [int(x) for x in input().split()]
    day = (999-y)*195 + (999-y)//3*5
    if y%3 == 0:
        day += (10-m)//2
    day += (10-m)*19 + (10-m)
    if y%3 != 0 and m%2 == 0:
        day += (19-d)
    else:
        day += (20-d)
    print(day+1)
def day(y, m, d):
    days = 0
    days += (y-1)*195
    days += (y-1)//3*5
    days += (m-1)*19
    if y%3 == 0:
        days += (m-1)
    else:
        days += m//2
    days += (d-1)
    return days

def main():
    n = int(input())
    for _ in range(n):
        (y, m, d) = [int(x) for x in input().split()]
        print(day(1000,1,1) - day(y,m,d))

if __name__ == '__main__':
    main()