The Wedding Date
Submissions: 248   Accuracy:

13.67%

  Difficulty: Easy   Marks: 2

Raj and Simran are very close friends. They want to marry but Simran's parents are not ready. Simran's father is very superstitious and believes that wedding can only happen if they will ready to marry at a date given by him(dd mm yyyy format). Since Raj is a very busy person, he can't agree with this situation as he has to take a leave from his work. So Simran came through an idea that they will marry on the date that will consist of all the digits of the date given by his father with same occurrences i.e. only the positions of the digits alter. Since Simran has other jobs to do, you have to help her to find the nearest date(that comes after the date his father given to him) that can be formed by the digits that her father gave to her.

Input:
The first line contains an integer T denoting the number of test cases. Each test case contains three space-separated integers ddmm & 
yyyy denoting day, month and year.

Output Format :
For each test case print, a single line containing three space-separated digits dd mm 
yyyy that comes after altering the date given by his father. If no date is possible, then print -1.

Constraints:
1<=T<=10^3
1<=dd<=30
1<=mm<=12
1000<=yyyy<=9999
Note:
1. Consider every month will have exactly 30 days
2. dd and mm will always contain 2 digits if doesn't put a "0" ahead of them.

Example:
Input: 
 3
12 02 2014
09 05 1998
13 12 9999
Output: 
21 02 2014
05 09 1998
-1

Explanation:
Test case #1 :
If we change the positions of date 12 to 21 then it will be a valid date.
Test case #2:
Switch day with the month and we will get the nearest valid date.
Test case #3:
Since in a month we will have exactly 30 days so we cant change their relative positions and max value of 
yyyy is 9999, so we can't change it either.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: ar_kh_am
Author: motif


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.