Everyone Loves to Sleep solution codeforces – Vlad, like everyone else, loves to sleep very much.
Every day Vlad has to do 𝑛n things, each at a certain time. For each of these things, he has an alarm clock set, the 𝑖i-th of them is triggered on ℎ𝑖hi hours 𝑚𝑖mi minutes every day (0≤ℎ𝑖<24,0≤𝑚𝑖<600≤hi<24,0≤mi<60). Vlad uses the 2424-hour time format, so after ℎ=12,𝑚=59h=12,m=59 comes ℎ=13,𝑚=0h=13,m=0 and after ℎ=23,𝑚=59h=23,m=59 comes ℎ=0,𝑚=0h=0,m=0.
[Solution] Everyone Loves to Sleep solution codeforces
This time Vlad went to bed at 𝐻H hours 𝑀M minutes (0≤𝐻<24,0≤𝑀<600≤H<24,0≤M<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.
The first line of input data contains an integer 𝑡t (1≤𝑡≤1001≤t≤100) — the number of test cases in the test.
The first line of the case contains three integers 𝑛n, 𝐻H and 𝑀M (1≤𝑛≤10,0≤𝐻<24,0≤𝑀<601≤n≤10,0≤H<24,0≤M<60) — the number of alarms and the time Vlad went to bed.
The following 𝑛n lines contain two numbers each ℎ𝑖hi and 𝑚𝑖mi (0≤ℎ𝑖<24,0≤𝑚𝑖<600≤hi<24,0≤mi<60) — the time of the 𝑖i alarm. It is acceptable that two or more alarms will trigger at the same time.
Numbers describing time do not contain leading zeros.
[Solution] Everyone Loves to Sleep solution codeforces
Output 𝑡t 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.
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