The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Young Matt and Jeff loved playing with numbers. One fine day, when Matt's little brother Paul, was at his math lesson with plastic number toys i.e. plastic toys in shape of digits 0 to 9, Matt and Jeff decided to play a game.
Paul had left the plastic numbers arranged to form a number N.
The rules of the game were as follows:
What number should the first player form, so that he always wins?
An integer T (1 = T = 100) denoting number of test cases followed by T lines each containing an integer N, the number Paul has formed. The number of digit in N is D(1 = D = 100000).
For each test case, output a number which first player should form so that he wins, in a separate line.
If there is no winning strategy for first player, then output -1.
Input: 3 17 81 123 Output: 71 -1 132
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll