Under construction

Still being built. Things may change

Fibonacci Half Sequence

Time limit2sMemory limit1024 MB

Summary
For n up to 10^18, find the lexicographically smallest sequence a with a[a[n]] = f[n], where f is 1, 2, 3, 5, ...; print -1 if a[n] exceeds 10^18.
Level

Hard8 of 10

Topics
Math, Recursion, Greedy
Solved
No attempts yet

Problem

The Fibonacci sequence fnf_n starts with 1 and 2 and is defined as follows.

  • f1=1f_1=1
  • f2=2f_2=2
  • For n≥3n\ge 3, fn=fn−1+fn−2f_n=f_{n-1}+f_{n-2}

The half sequence ana_n of this Fibonacci sequence is defined as follows.

  • ana_n is the lexicographically smallest sequence among all sequences that satisfy aan=fna_{a_n}=f_n for every positive integer nn.

Sequence ana_n is lexicographically smaller than bnb_n if there exists an ii such that aj=bja_j=b_j for every jj less than ii, and ai<bia_i<b_i.

Input

The first line contains the number of test cases TT. (1≤T≤10 000)(1\le T\le 10\,000)

Each of the next TT lines contains one value of nn. (1≤n≤1018)(1\le n\le 10^{18})

Output

For each nn, print ana_n on its own line. If an>1018a_n>10^{18}, print -1 instead.

Examples1

  1. Example 1

    Input
    7
    1
    2
    3
    4
    5
    6
    10000000
    
    Expected output
    1
    2
    3
    6
    13
    5
    -1