Fibonacci Representation

No attempts yetTime limit3sMemory limit128 MB

Problem

The Fibonacci sequence is a sequence of integers, called Fibonacci numbers, defined by:

  • F0=0F_0 = 0, F1=1F_1 = 1, and Fn=Fn2+Fn1F_n = F_{n-2} + F_{n-1} for n>1n > 1.

Its first terms are 0,1,1,2,3,5,8,13,21,34,55,0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, \dots

Byteasar studies how integers can be written as sums and differences of Fibonacci numbers. Right now he wants the minimum representation: one that uses the fewest Fibonacci numbers, for a given positive integer kk. The same Fibonacci number may be used more than once. For example, 1010, 1919, 1717, and 10701070 can be written with as few as 22, 22, 33, and 44 Fibonacci numbers, respectively:

  • 10=5+510 = 5 + 5
  • 19=21219 = 21 - 2
  • 17=13+5117 = 13 + 5 - 1
  • 1070=987+89511070 = 987 + 89 - 5 - 1

Write a program that, for a given positive integer kk, finds the minimum number of Fibonacci numbers whose signed sum (using additions and subtractions) equals kk.

Input

The first line contains a single positive integer pp (1p101 \le p \le 10), the number of queries. Each of the next pp lines contains one positive integer kk (1k410171 \le k \le 4 \cdot 10^{17}).

Output

For each query, print on its own line the minimum number of Fibonacci numbers needed to represent kk as their sum or difference.