CF1857B.Maximum Rounding

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Maximum Rounding

Given a natural number xx. You can perform the following operation:

  • choose a positive integer kk and round xx to the kk-th digit

Note that the positions are numbered from right to left, starting from zero. If the number has kk digits, it is considered that the digit at the kk-th position is equal to 00.

The rounding is done as follows:

  • if the digit at the (k1)(k-1)-th position is greater than or equal to 55, then the digit at the kk-th position is increased by 11, otherwise the digit at the kk-th position remains unchanged (mathematical rounding is used).
  • if before the operations the digit at the kk-th position was 99, and it should be increased by 11, then we search for the least position kk' (k>kk' \gt k), where the digit at the kk'-th position is less than 99 and add 11 to the digit at the kk'-th position. Then we assign k=kk=k'.
  • after that, all digits which positions are less than kk are replaced with zeros.

Your task is to make xx as large as possible, if you can perform the operation as many times as you want.

For example, if xx is equal to 34513451, then if you choose consecutively:

  • k=1k=1, then after the operation xx will become 34503450
  • k=2k=2, then after the operation xx will become 35003500
  • k=3k=3, then after the operation xx will become 40004000
  • k=4k=4, then after the operation xx will become 00

To maximize the answer, you need to choose k=2k=2 first, and then k=3k=3, then the number will become 40004000.

Input

The first line contains a single integer tt (1t1041\le t\le 10^4) — the number of test cases.

Each test case consists of positive integer xx with a length of up to 21052 \cdot 10^5. It is guaranteed that there are no leading zeros in the integer.

It is guaranteed that the sum of the lengths of all integers xx over all test cases does not exceed 21052 \cdot 10^5.

Output

For each set of input data, output the maximum possible value of xx after the operations. The number should not have leading zeros in its representation.

Note

In the first sample, it is better not to perform any operations.

In the second sample, you can perform one operation and obtain 1010.

In the third sample, you can choose k=1k=1 or k=2k=2. In both cases the answer will be 100100.

Samples

10
1
5
99
913
1980
20444
20445
60947
419860
40862016542130810467
1
10
100
1000
2000
20444
21000
100000
420000
41000000000000000000

在线编程 IDE

建议全屏模式获得最佳体验