406554: GYM102439 H Nonfibonacci numbers

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Nonfibonacci numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Fibonacci numbers — well-known integer sequence, where $$$F_0 = 0$$$, $$$F_1 = 1$$$ and $$$F_n = F_{n - 1} + F_{n - 2}$$$ for $$$n > 1$$$.

Lesha doesn't like this sequence and all the numbers $$$x$$$, such that we can get positive Fibonacci number by crossing out several digits. For example, Lesha doesn't like number $$$193$$$, because it is possible to cross $$$9$$$ out and get $$$F_6 = 13$$$.

Your task is to find the number of integers from $$$0$$$ to $$$n$$$ which Lesha likes.

Input

The first line contains a single integer $$$t$$$ — the number of test cases.

Each of the following $$$t$$$ lines contains a single integer $$$n$$$ — number, until which you have to count numbers which Lesha likes.

$$$$$$1 \le t \le 10$$$$$$ $$$$$$0 \le n \le 10^{18}$$$$$$

Output

Print $$$t$$$ lines, each of them should contain a single integer — the answer for the test case.

ExampleInput
2
4
2019
Output
2
125
Note

In the first test suitable numbers are 0 and 4.

加入题单

上一题 下一题 算法标签: