#5041. Problem 1. Roundabout Rounding

0

Problem 1. Roundabout Rounding

Problem 1. Roundabout Rounding

USACO 2024 December Contest, Bronze

Bessie the cow is back in school! She has started doing her math homework in which she is tasked to round positive integers to powers of 1010.

To round a positive integer aa to the nearest 10b10^b, where bb is a positive integer, Bessie first locates the bb'th digit from the right. Let xx denote this digit.

If x5x \geq 5, Bessie adds 10b10^b to aa.

Then, Bessie sets all the digits including and to the right of the bb'th digit from the right to be 00.

For instance, if Bessie wanted to round 456456 to the nearest 10210^2 (hundred), Bessie would first locate the 22nd digit from the right which is 55. This means x=5x = 5. Then since x5x \geq 5, Bessie adds 100100 to aa. Finally, Bessie sets all the digits in aa to the right of and including the 22nd digit from the right to be 00, resulting in 500500.

However, if Bessie were to round 446446 to the nearest 10210^2, she would end up with 400400.

After looking at Bessie's homework, Elsie thinks she has invented a new type of rounding: chain rounding. To chain round to the nearest 10b10^b, Elsie will first round to the nearest 10110^1, then the nearest 10210^2, and so on until the nearest 10b10^b.

Bessie thinks Elsie is wrong, but is too busy with math homework to confirm her suspicions. She tasks you to count how many integers xx at least 22 and at most NN (1N1091 \leq N \leq 10^{9}) exist such that rounding xx to the nearest 10P10^P is different than chain rounding to the nearest 10P10^P, where PP is the smallest integer such that 10Px10^P \geq x.

INPUT FORMAT (input arrives from the terminal / stdin):

You have to answer multiple test cases.

The first line of input contains a single integer TT (1T1051 \leq T \leq 10^5) denoting the number of test cases. TT test cases follow.

The first and only line of input in every test case contains a single integer NN. All NN within the same input file are guaranteed to be distinct.

OUTPUT FORMAT (print output to the terminal / stdout):

Output TT lines, the ii'th line containing the answer to the ii'th test case. Each line should be an integer denoting how many integers at least 22 and at most NN exist that are different when using the two rounding methods.

SAMPLE INPUT:


4
1
100
4567
3366

SAMPLE OUTPUT:


0
5
183
60

Consider the second test case in the sample. 4848 should be counted because 4848 chain rounded to the nearest 10210^2 is 100100 (485010048\to 50\to 100), but 4848 rounded to the nearest 10210^2 is 00.

In the third test case, two integers counted are 4848 and 480480. 4848 chain rounds to 100100 instead of to 00 and 480480 chain rounds to 10001000 instead of 00. However, 6767 is not counted since it chain rounds to 100100 which is 6767 rounded to the nearest 10210^2.

SCORING: Inputs 2-4: N103N\le 10^3Inputs 5-7: N106N\le 10^6Inputs 8-13: No additional constraints.

Problem credits: Weiming Zhou