from collections import defaultdict d = defaultdict(int) def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] t = int(input()) for _ in range(t): n = int(input()) nums = [] while True: if d[n] : print(d[n]) break else: dx = len(make_divisors(n)) if n != dx: nums.append(n) n -= dx else: print(n) d[n] = n for num in nums: d[num] = n break