import sys def I(): return int(sys.stdin.readline().rstrip()) def phi(n): ans = n for i in range(2,int(n**.5) + 1): if n % i == 0: ans = (ans*(i-1))//i while n % i == 0: n //= i if n == 1: # 時間短縮 break if n != 1: ans = (ans*(n-1))//n return ans def divisor(n): # nの約数全列挙 res = [] for i in range(1,int(n**.5)+1): if n % i == 0: res.append(i) if i != n//i: res.append(n//i) return res T = I() for _ in range(T): N = I() # 2**K == 1 (mod 2*N-1) たる最小のKを求める x = phi(2*N-1) div = divisor(x) div.sort() for d in div: if pow(2,d,2*N-1) == 1 or N == 1: print(d) break