P27878 [洛谷] [Language Month Competition 202309] Coconut Milk Country
普及
题目描述

Problem Background

Fusu dreams of living in Coconut Milk Country. The inhabitants of this country are all adorable coconut milks, who live happily without worrying about the outside world.

Problem Description

A day in Coconut Milk Country consists of $n$ hours. The $i$-th hour ($0 \leq i < n$) has $i + 1$ minutes, and the $j$-th minute ($0 \leq j \leq i$) of the $i$-th hour has $10j + 1$ seconds.

Note that hours, minutes, and seconds are all counted from $0$.

Given the starting time $t_1 = A:B:C$, which means $t_1$ is at $A$ hours, $B$ minutes, and $C$ seconds, and the ending time $t_2 = E:F:G$, which means $t_2$ is at $E$ hours, $F$ minutes, and $G$ seconds.

It is known that the time at $t_2$ is not earlier than the time at $t_1$, and the interval between them is less than one day.

Please calculate the number of seconds that have passed between $t_1$ and $t_2$.

Input Format

This problem contains multiple sets of test data. The first line is an integer representing the number of data sets $T$.

The next $T$ lines each contain seven integers, representing the data for one set: $n, A, B, C, E, F, G$.

Output Format

For each set of data, output a single integer on a new line representing the answer.

Sample Input and Output

Input Sample #1

1
10 3 2 11 3 3 0

Output Sample #1

10

Input Sample #2

1
2 1 1 3 0 0 0

Output Sample #2

8

Notes

Explanation of Sample 2

In Coconut Milk Country, a day has $2$ hours, namely the $0$-th and $1$-st hours. The $1$-st hour has $2$ minutes, namely the $0$-th and $1$-st minutes. The $1$-st minute has $10 \times 1 + 1 = 11$ seconds. Starting from the $3$-rd second of the $1$-st hour and $1$-st minute, the next moments are the $4, 5, 6, 7, 8, 9, 10, 0$-th seconds (where the last second is the first second of the next day), totaling eight seconds.

Data Range and Constraints

  • For $30\%$ of the data, the time represented by $t_2$ is not earlier than the time represented by $t_1$ within one day.
  • For $60\%$ of the data, $n \leq 50$, guaranteeing that the sum of answers within a single test point does not exceed $10^8$.
  • For $100\%$ of the data, $1 \leq T \leq 5 \times 10^3$, $1 \leq n \leq 10^5$, $0 \leq B \leq A < n$, $C \leq 10B$. $0 \leq F \leq E < n$, $G \leq 10E$, guaranteeing that the sum of $n$ within a single test point does not exceed $1.5 \times 10^8$.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 10 3 2 11 3 3 0
样例输出
10