New update is available. Click here to update.


Posted: 19 Mar, 2021
Difficulty: Moderate


Try Problem

Ninja has his own philosophy. He thinks that if his watch started showing next closet time he will be able to do all his work on time. As if his watch shows next closet time, then he would think that the deadline is near and he will be able to do his work before deadline.

So your task is to write a code that can return the next closet time you are given a time represented in the format “HH: MM” by using the current digits. There is no limit on how many times a digit can be used.

Input Format:

The first line of input contains a ‘T’ number of test cases.

The first line of input of each test case contains a string 'TIME', which represents the time in “HH: MM” format.

Output Format:

For each test case, return the string which is the next closest time to the given string.
You are not required to print anything explicitly. It has already been taken care of. Just implement the given function.


1 <= T <= 100 
| TIME | = 5

Time Limit: 1 sec