Largest Divisibility Test
Submissions: 686   Accuracy:

28%

  Difficulty: Medium   Marks: 4

Babul’s favourite number is 17. He likes the numbers which are divisible by 17. This time what he does is that he takes a number N and tries to find the largest number which is divisible by 17, by rearranging the digits. As the number increases he gets puzzled with his own task. So you as a programmer have to help him to accomplish his task.

Note: If the number is not divisible by rearranging the digits, then print “Not Possible”. N may have leading zeros.

Input:
The first line of input contains an integer T denoting the no of test cases. Each of the next T lines contains the number N.

Output:
For each test case in a new line print the desired output.

Constraints:
1<=T<=100
1<=N<=10^10

Example:
Input:

4
17
43
15
16

Output:
17
34
51
Not Possible

 

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

Author: Prithwish Dasgupta


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.