Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Given an integer A that contains n > 1 digits. You are asked to remove exactly one digit to make the result number is divisible by 6, also make it biggest possible.
The first line contains an integer T, denotes the number of test cases. Each test case is described by an integer A in a single line.
Each test case, output the answer on a single line (it's allowed to delete a digit such that the resulting number contains leading zeroes, you shouldn't remove them in this case). If it is impossible to make the result number satisfies the above condition, output -1.
- 1 ≤ T ≤ 100
- 2 ≤ n ≤ 105
- A will not contain leading zeroes
- the sum of n over all test cases ≤ 106
- Subtask #1 (30 points): the sum of n over all test cases ≤ 2000
- Subtask #2 (70 points): original constrains
Input: 3 123 100222 10003 Output: 12 00222 -1
|Tags||ad-hoc, chemthan, easy, ltime53|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions