Hyeonseong often goes to an internet cafe to play online games. The cafe charges as follows.
The regular rate is 1000 won per hour. Going even one minute past a full hour adds the price of another whole hour, so m minutes at the regular rate cost 1000×⌈m/60⌉ won.
A night pass costs 5000 won and can be used from 22:00 until 08:00 the next morning. If the session spans several days, a separate pass can be bought for each night.
Switching from the regular rate to a night pass settles the regular charge accrued so far. So a session that runs on the regular rate, then a night pass, then the regular rate again is billed for two separate regular periods.
Given the time Hyeonseong starts playing and how long he plays, write a program that computes the smallest amount he has to pay. Once he starts, he plays without a break for the whole time.
The first line has the number of test cases T (1≤T≤10).
Each test case is one line of the form HH:MM D. A colon separates HH and MM, and a single space separates MM and D. HH:MM is the time Hyeonseong starts playing, meaning he starts at HH hours MM minutes. Times run from 00:00 to 23:59, with the hour and the minute both written in two digits, so a single digit gets a leading zero. D is an integer giving how many minutes he plays, and human stamina caps it at three days (1≤D≤4320).
For each test case, print the smallest amount Hyeonseong has to pay, one per line. Leave out the currency unit.