CF1714A.Everyone Loves to Sleep

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Everyone Loves to Sleep

Vlad, like everyone else, loves to sleep very much.

Every day Vlad has to do nn things, each at a certain time. For each of these things, he has an alarm clock set, the ii-th of them is triggered on hih_i hours mim_i minutes every day (0hi<24,0mi<600 \le h_i \lt 24, 0 \le m_i \lt 60). Vlad uses the 2424-hour time format, so after h=12,m=59h=12, m=59 comes h=13,m=0h=13, m=0 and after h=23,m=59h=23, m=59 comes h=0,m=0h=0, m=0.

This time Vlad went to bed at HH hours MM minutes (0H<24,0M<600 \le H \lt 24, 0 \le M \lt 60) and asks you to answer: how much he will be able to sleep until the next alarm clock.

If any alarm clock rings at the time when he went to bed, then he will sleep for a period of time of length 00.

Input

The first line of input data contains an integer tt (1t1001 \le t \le 100) — the number of test cases in the test.

The first line of the case contains three integers nn, HH and MM (1n10,0H<24,0M<601 \le n \le 10, 0 \le H \lt 24, 0 \le M \lt 60) — the number of alarms and the time Vlad went to bed.

The following nn lines contain two numbers each hih_i and mim_i (0hi<24,0mi<600 \le h_i \lt 24, 0 \le m_i \lt 60) — the time of the ii alarm. It is acceptable that two or more alarms will trigger at the same time.

Numbers describing time do not contain leading zeros.

Output

Output tt lines, each containing the answer to the corresponding test case. As an answer, output two numbers  — the number of hours and minutes that Vlad will sleep, respectively. If any alarm clock rings at the time when he went to bed, the answer will be 0 0.

Samples

3
1 6 13
8 0
3 6 0
12 30
14 45
6 0
2 23 35
20 15
10 30
1 47
0 0
10 55

在线编程 IDE

建议全屏模式获得最佳体验