Planet Lapituletti


- 某星球的时间和地球上的时间一样,但是一天有 $h$ 小时,每小时有 $m$ 分钟。 - 该星球使用的电子钟和地球的类似,以 `HH:MM` 的格式表示时间。具体来说,冒号前的数显示的是十进制小时数,冒号后的数显示的是十进制分钟数,不满两位数的在前面补足前导 $0$。和地球类似,该星球的小时数为 $0$ 到 $h-1$,分钟数为 $0$ 到 $m-1$。每个数字的表示方式见第一幅图(**请注意,$1$ 显示在格子中间而不是格子右边**)。 - 该星球使用一个镜子,将时钟上显示的时间反射到镜子上。居民们如果看到镜子上显示的有效的数字,而这些数字所组成的新时间又是有效的,那么他们会很高兴。 - 现在,给定 $T$ 组数据,每组数据给定 $h,m$ 以及当前时刻 `HH:MM`,对于每组数据,请告诉居民们能使他们高兴的,而且距离当前时刻最近的即将到来的时刻(**请注意,这个时刻可能会是第二天的某一时刻**)。 - $1\leqslant T,h,m\leqslant 100$。 Translated by Eason_AC 2021.3.7


The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts $ h $ hours and each hour lasts $ m $ minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from $ 0 $ to $ h-1 $ and minutes are numbered from $ 0 $ to $ m-1 $ . ![]('s how the digits are displayed on the clock. Please note that digit $ 1 $ is placed in the middle of its position. A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day). The image of the clocks in the mirror is reflected against a vertical axis. ![]( reflection is not a valid time. ![]( The reflection is a valid time with $ h=24 $ , $ m = 60 $ . However, for example, if $ h=10 $ , $ m=60 $ , then the reflection is not a valid time. An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment $ s $ and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid. It can be shown that with any $ h $ , $ m $ , $ s $ such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest. You are asked to solve the problem for several test cases.



The first line contains a single integer $ T $ ( $ 1 \le T \le 100 $ ) — the number of test cases. The next $ 2 \cdot T $ lines contain the description of test cases. The description of each test case consists of two lines. The first line of a test case contains two integers $ h $ , $ m $ ( $ 1 \le h, m \le 100 $ ). The second line contains the start time $ s $ in the described format HH:MM.


For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.


输入样例 #1

24 60
24 60
90 80
1 100
10 10

输出样例 #1



In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct. ![](