1303 - Time is Money!   

Description

Peter is an employee of certain company. Since the policy of company, his salary is related to the type of works and the corresponding time. For example, if Peter spent 2 hours in updating server, and company paid him $600 per hour, then he earned $1200.

Now you have the list of Peter's works, please compute Peter's salary.

Input

The first line is an integer T(<=100) meaning the number of test cases in the input file. In each test case, it begins with N, the number of works(N<=103), come up with N works' details, P TS TF. P(03) is the payment of work per hour, TS means start time, and TF means finish time. All three numbers are integer, you can see sample input for more details.

For simplicity, we assume that all works are done in one day, no durations cross two or more days. Moreover, the durations of any two works doesn't overlap each other and the time in one day is from 00:00 to 23:59. Besides, if the duration is less than one hour, we take this duration as if he works for an hour. For instance, a duration 1 hour and 23 minutes is counted as 2 hours.

Output

For each test case, output test case number and the salary in a line. There should be an empty line between two adjacent test cases.

See sample output for more details.

Sample Input  Download

Sample Output  Download

Tags




Discuss