import sys def input(): return sys.stdin.buffer.readline()[:-1] def phi(x): prime = [] i = 2 y = x while i*i <= x: if y%i == 0: prime.append(i) while y%i == 0: y //= i i += 1 if y > 1: prime.append(y) res = x for p in prime: res = res * (p-1) // p div = [] i = 1 while i * i <= res: if res % i == 0: div.append(i) div.append(res // i) i += 1 return div for _ in range(int(input())): n = int(input()) * 2 if n == 1: print(1) continue div = phi(n-1) #print(div) ans = n for d in div: if pow(2, d, n-1) == 1: ans = min(ans, d) print(ans)