/**
 * @(#)QuickFib.java
 *
 *
 * @author Juliet
 * @version 1.00 2011/7/25
 *
 * For BHCSI Contest Problem: Quick Fib
 */
 
import java.util.*;
import java.io.*;

public class fib { 

	//Main method. 
    public static void main(String[] args) throws Exception {

    	Scanner stdin = new Scanner(new File("fib.in"));
    	
    	// Just making this big enough
    	int[] fib = new int[50];
    	
    	// Fill in with Fibonacci numbers.
    	fib[0] = 0;
    	fib[1] = 1;
    	for (int i=2; fib[i-1]<10000000; i++)
    		fib[i] = fib[i-1] + fib[i-2];
    		
    	// Read in the number of cases.
    	int numCases = stdin.nextInt();

		// Process each case.
    	for (int i=1; i<=numCases; i++) {
			
			int julietnumber = stdin.nextInt();
			int skip = numFibsBelow(julietnumber, fib);
			System.out.println(julietnumber-skip);
    	}

    }
    
    // Returns the number of Fibonacci numbers less than n.
    public static int numFibsBelow(int n, int[] fibs) {
    	
    	// Find the first Fib number greater than n.
    	int i = 2;
    	while (fibs[i] < n) i++;
    	
    	// 0 and 1 are redundant in our array by the problem definition,
    	// so subtract out 2 from i to get the correct answer.
    	return i-2;
    	
    }

    
}