import sys
from typing import List

TABLE: List[List[int]] = [[1], [1], [1], [1, 2], [1, 3]]


def load_nums(count: int) -> List[int]:
    #return [int(x) for line in sys.stdin.readlines() for x in line.split()]
    ls = []
    for i in range(count):
        ls.append(int(input()))
    return ls
    


def acc_line(n: int) -> List[int]:
    tmp: List[int] = [1]
    found: bool = False

    # print("LOOKING FOR ", n)
    while not found:
        tmp = [1]
        line = TABLE[len(TABLE)-1]
#        print("-------", len(line))
#        print(f'line: {line}')
        for i in range(1, len(line)):
#            print("i: ", i)
            x = line[i - 1] + line[i]
            tmp.append(x)
            if x == n:
                found = True

        if len(TABLE) % 2:
            tmp.append(2*line[len(line) - 1])
        
#        print("tmp: ", tmp)
        TABLE.append(tmp)

def grow_table(n: int):
    acc_line(n)


def find_row(n: int) -> int:
#    print(TABLE)
    if n == 1:
        return 1
    for i, line in enumerate(TABLE):
        # print(line)
        for x in line:
            if x == n:
                return i
    grow_table(n)
    return find_row(n)


if __name__ == '__main__':
    count = int(input())
    nums = load_nums(count)

    for n in nums[:count]:
        print(find_row(n))

