Under construction

Still being built. Things may change

Millennium

Time limit1sMemory limit128 MB

Summary
Given a birthdate in a fictional 10-month calendar with alternating 19 and 20 day months, find days until year 1000, month 1, day 1.
Level

Easy3 of 10

Topics
Math, Implementation, Simulation, Prefix sum
Solved
No attempts yet

Problem

A wise king proclaimed a new calendar. “Let tomorrow be the first day of this calendar, that is, day 1 of month 1 of year 1. A year has ten months, from month 1 through month 10, and begins with a big month. A common year begins with a big month, after which small months and big months alternate. Thus month 1 is a big month, month 2 a small month, month 3 a big month, …, and the last month, month 10, a small month. A big month has 20 days and a small month has 19 days. However, years that are multiples of three, that is years 3, 6, 9, and so on, have ten big months and no small month.”

Many years have passed since the calendar came into use. To celebrate the millennium day (year 1000, month 1, day 1), a royal lottery will be held to send gifts to those who have lived exactly as many days as the number drawn. Write a program that, given a birthdate, computes the number of days from that birthdate to the millennium day.

Input

The input is given in the following format.

n
Y1 M1 D1
Y2 M2 D2
...
Yn Mn Dn

The first line contains a positive integer nn (at most 100), the number of datasets. It is followed by nn datasets. Each dataset is a single line containing three positive integers YiY_i (<1000< 1000), MiM_i (≤10\le 10), and DiD_i (≤20\le 20) — the year, month, and day of a person's birthdate in the king's calendar — separated by spaces.

Output

For each birthdate, print on its own line the number of days from the birthdate, inclusive, to the millennium day, exclusive. Each output line must contain nothing but this number.

Examples1

  1. Example 1

    Input
    8
    1 1 1
    344 3 1
    696 5 1
    182 9 5
    998 8 7
    344 2 19
    696 4 19
    999 10 20
    
    Expected output
    196470
    128976
    59710
    160715
    252
    128977
    59712
    1