from collections import defaultdict import sys input = sys.stdin.readline inf = 10**18 def main(): N = int(input()) mod = 2*N-1 d = defaultdict(int) n = int(mod**0.5) + 1 ans = inf for p in range(1, n+1)[::-1]: val = pow(2, n*p, mod) d[val] = p for q in range(n)[::-1]: val = pow(2, q, mod) if d[val]: K = n * d[val] - q ans = min(ans, K) print(ans) T = int(input()) for _ in range(T): main()