Stay up Late and Wake up Early
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

To tell the truth, creating a great number of programming problems is a huge project. During a period of time, Little Gyro usually stays up late and feels quite exhausted because of it, however, due to the morning classes or for some other reason the next day, Little Gyro has to wake up early tomorrow morning, so he decides to set an alarm.
One day, Little Gyro decides that he needs to wake up at exactly hh:mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. Little Gyro will then press the snooze button every x minute until hh:mm is reached, and only then will he wake up. Now Little Gyro wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13:07 and 17:27 are lucky, while 00:48 and 21:34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Little Gyro can set so that he can wake at hh:mm.
Formally, find the smallest possible non-negative integer y such that the time representation of the time xy minutes before hh:mm contains the digit '7'.
Please note that Little Gyro uses 24-hour clock, so after 23:59 comes 00:00.

输入描述:

There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ 300), indicating the number of test cases. For each test case:
Each line contains a single integer x (1 ≤ x ≤ 60) and two two-digit integers, hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59), indicating the time for the snooze button and the wake-up time within 24-hours format, separate by a space.

输出描述:

For each test case, output the minimum number of times y that Little Gyro needs to press the button, and the initial time Little Gyro sets for the alarm within 24-hours format, separate by a space.
示例1

输入

复制
2
3 06:23
5 13:07

输出

复制
2 06:17
0 13:07

备注:

In the first sample, Little Gyro needs to wake up at 06:23. So, he can set his alarm at 06:17. He would press the snooze button when the alarm rings at 06:17 and at 06:20.<br />In the second sample, Little Gyro can set his alarm at exactly 13:07 which is lucky.