Problem6812--Find the AFei Numbers

6812: Find the AFei Numbers

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

AFei loves numbers. He defines the natural number containing "520" as the AFei number, such as 1234520, 8752012 and 5201314. 
Now he wants to know how many AFei numbers are not greater than $n$.

Input

The first line contains an integer $T\ (1 \leq T \leq 100)$.
The following $T$ lines contain an interger $n\ (0 \leq n \leq 10^{18})$.

Output

For the last $T$ lines, output the total numbers of AFei numbers that are not greater than $n$.

Sample 1 Input

2
1000
5520

Sample 1 Output

1
16
For the first case, only $520$ is AFei number.
For the second case, $520,1520, 2520, 3520, 4520, 5200, 5201, 5202, 5203, 5204, 5205, 5206, 5207, 5208, 5209, 5520$ are AFei number. So there are $16$ AFei numbers.

HINT

相同题目:牛客网

Source/Category

数位dp