def solve(): n = 2 * int(input()) - 1 if n == 1: print(1) return eu = n x = n for i in range(2, int(n ** 0.5 + 1)): if x % i == 0: eu *= i - 1 eu //= i while x % i == 0: x //= i if x != 1: eu *= x - 1 eu //= x div = [] for i in range(1, int(n ** 0.5 + 1)): if eu % i == 0: div.append(i) div.append(eu // i) div.sort() for i in div: if pow(2, i, n) == 1: print(i) return for _ in range(int(input())): solve()