import sys import math import random def is_prime(n): if n < 2: return False for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]: if n % p == 0: return n == p d = n - 1 s = 0 while d % 2 == 0: d //= 2 s += 1 for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]: if a >= n: continue x = pow(a, d, n) if x == 1 or x == n - 1: continue for _ in range(s - 1): x = pow(x, 2, n) if x == n - 1: break else: return False return True def pollards_rho(n): if n % 2 == 0: return 2 if n % 3 == 0: return 3 if n % 5 == 0: return 5 while True: c = random.randint(1, n - 1) f = lambda x: (pow(x, 2, n) + c) % n x, y, d = 2, 2, 1 while d == 1: x = f(x) y = f(f(y)) d = math.gcd(abs(x - y), n) if d != n: return d def factor(n): factors = [] def _factor(n): if n == 1: return if is_prime(n): factors.append(n) return d = pollards_rho(n) _factor(d) _factor(n // d) _factor(n) factors.sort() return factors def factorize(n): if n == 1: return {} factors = factor(n) res = {} for p in factors: res[p] = res.get(p, 0) + 1 return res def find_smallest_prime_not_dividing(X): if X == 1: return 2 for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]: if X % p != 0: return p p = 101 while True: if p * p > X: return p if X % p != 0 and is_prime(p): return p p += 2 def solve(): input = sys.stdin.read().split() T = int(input[0]) for i in range(1, T + 1): X = int(input[i]) if X == 1: print(2) continue factors = factorize(X) p_add = find_smallest_prime_not_dividing(X) Y_add = X * p_add Y_mod = None for p in factors: e = factors[p] current = X * (p ** (e + 1)) if Y_mod is None or current < Y_mod: Y_mod = current if Y_mod is None: ans = Y_add else: ans = min(Y_add, Y_mod) print(ans) if __name__ == "__main__": solve()