A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day of the month of the year . Each year consists of months, from month through month , 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 th and last month a small one. A big month consists of days and a small month consists of days. However years which are multiples of three, that are year , year , year , and so on, shall consist of 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 , month , day ), 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.
The input is formatted as follows.
Y_1 M_1 D_1 Y_2 M_2 D_2 ... Y_n M_n D_n
Here, the first line gives the number of datasets as a positive integer (n \leq 100). It is followed by datasets. Each dataset is formatted in a line and gives three positive integers, Y_i (Y_i < 1000), M_i (M_i \leq 10), and D_i (D_i \leq 20), that correspond to the year, month and day, respectively, of a person's birthdate in the king's calendar. These three numbers are separated by a space.
For the birthdate specified in each dataset, print in a line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Output lines should not contain any character other than this number.
Example 1