CF BUDDY
← Problems·

1626B · Minor Reduction

1100 · greedy, strings

Problem: You are given a decimal representation of an integer xx without leading zeros.

You have to perform the following reduction on it exactly once: take two neighboring digits in xx and replace them with their sum without leading zeros (if the sum is 00, it's represented as a single 00).

For example, if x=10057x = 10057, the possible reductions are:

  • choose the first and the second digits 11 and 00, replace them with 1+0=11+0=1; the result is 10571057;
  • choose the second and the third digits 00 and 00, replace them with 0+0=00+0=0; the result is also 10571057;
  • choose the third and the fourth digits 00 and 55, replace them with 0+5=50+5=5; the result is still 10571057;
  • choose the fourth and the fifth digits 55 and 77, replace them with 5+7=125+7=12; the result is 1001210012.

What's the largest number that can be obtained?

Input Format: The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of testcases.

Each testcase consists of a single integer xx (10x<1020000010 \le x < 10^{200000}). xx doesn't contain leading zeros.

The total length of the decimal representations of xx over all testcases doesn't exceed 21052 \cdot 10^5.

Output Format: For each testcase, print a single integer — the largest number that can be obtained after the reduction is applied exactly once. The number should not contain leading zeros.

Note: The first testcase of the example is already explained in the statement.

In the second testcase, there is only one possible reduction: the first and the second digits.

Sample Cases

Case 1

Input

2
10057
90

Output

10012
9

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback