Largest Even Number
Submissions: 2918   Accuracy:

32.47%

  Difficulty: Easy   Marks: 2

As usual Babul is back with his problem but this time with numbers. In his problem there is a number P(always a whole number) with N digits. Now he started finding out the largest possible even number formed by rearranging this N digit number. For example consider number 1324, after rearranging the digits the largest even number possible is 4312.

Note: In case the number does not contain any even digit then output the largest odd number possible.

Input:
The first line of input will contain an integer T which is the number of testcases. Each of the next T lines will contain a number P.

Output:
For each test case in a new line print the required result.

Constraints:
1 <= T <= 100
1 <= N <= 1000

Example:
Input:

5
1324
3415436
1023422
03517
3555

Output:
4312
6543314
4322210
75310
5553

Explanation:
Testcase 1:
The largest even number formed will be: 4312.

 

** 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.