Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Largest Divisibility Test
Medium Accuracy: 34.65% Submissions: 1256 Points: 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

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Largest Divisibility Test

Output Window