P16210 [ECUSTPC 2025] Time Puzzle
Description
Maddy’s digital watch was smashed. Surprisingly, the digits on it flew out and fell onto the ground.
Now she picked up two numbers from the ground. Please help her use these two numbers to form a new 24-hour time $Time$, or tell her that it is impossible.
The required 24-hour time is a string in the format HH:MM, and it must satisfy the following requirements:
- HH and MM are non-negative integers with at most two digits. If a number has only one digit, a leading $0$ should be added.
- The range of HH is $0 \le HH \le 23$, and the range of MM is $0 \le MM \le 59$.
- HH, MM, and the two given numbers must correspond one-to-one without omission or duplication. Note that you may swap the order of the two given numbers.
Input Format
The first line contains an integer $T$ ($1 \le T \le 10^4$), representing the number of test cases.
For each test case, the only line contains two integers $a$ and $b$ ($0 \le a, b \le 99$), representing the two numbers Maddy picked.
Output Format
For each test case, if you can form a 24-hour time using the given two numbers, output one line containing a string $Time$, representing the time you constructed. If there are multiple valid answers, you may output any one of them.
Otherwise, output one line containing an integer $-1$.
Explanation/Hint
### Sample 1 Explanation
For the 1st sample case, we can see that:
- $09$ and $41$ are non-negative integers with at most two digits, and a leading $0$ is added for the one-digit number.
- $09$ and $41$ satisfy the corresponding range limits.
- $09$ and $41$ correspond one-to-one with the given $9$ and $41$ without omission or duplication.
Note that $41:09$ is not a valid answer because it does not satisfy the corresponding range limits.
For the 2nd sample case, it is easy to see that no matter how you swap the order, you cannot form a valid 24-hour time.
Translated by ChatGPT 5