Repeated Rounding

Interview

Time limit1sMemory limit128 MB

Summary
Round each integer repeatedly at increasing place values (ones, tens, hundreds, ...) using round-half-up until the value no longer exceeds the current threshold.
Level

Medium4 of 10

Topics
Math, Implementation, Simulation
Solved
No attempts yet

Problem

You are given an integer xx. Round it repeatedly according to the following rules.

  • If xx is greater than 1010, round at the ones place, i.e. change it to the nearest multiple of 1010.
  • If the result is greater than 100100, round at the tens place, i.e. change it to the nearest multiple of 100100.
  • If the result is greater than 10001000, round at the hundreds place.
  • Continue this way: while the rounded result is greater than the next threshold (10,100,1000,…10, 100, 1000, \dots), move one place higher and round again.

Rounding is round-half-up: if the part being dropped is at least half of the place value, round up; otherwise round down (for the ones place, a ones digit of 55 or more rounds up). When you can no longer round (the current value is at most the current threshold), that value is the final result.

Input

The first line contains the number of test cases nn. Each of the following lines contains one integer xx to be rounded. (0≤x≤999999990 \le x \le 99999999)

Output

For each test case, print the result of rounding the given integer by the rules above, one per line.

Examples1

  1. Example 1

    Input
    9
    15
    14
    4
    5
    99
    12345678
    44444445
    1445
    446
    
    Expected output
    20
    10
    4
    5
    100
    10000000
    50000000
    2000
    500