import bisect def make_twin_prime_products(limit, prod_limit): is_prime = [True] * (limit + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(limit**0.5) + 1): if is_prime[i]: for j in range(i*i, limit + 1, i): is_prime[j] = False twin_products = [] for i in range(2, limit - 1): if is_prime[i] and is_prime[i+2]: prod = i * (i+2) if prod > prod_limit: break twin_products.append(prod) return twin_products MAX_N = 10**14 prime_limit = int((MAX_N)**0.5) + 100 p_L = make_twin_prime_products(prime_limit, MAX_N) T = int(input()) for _ in range(T): N = int(input()) idx = bisect.bisect_left(p_L, N) if idx < len(p_L) and p_L[idx] == N: print(N) else: if idx == 0: print(-1) elif idx == len(p_L): print(p_L[idx - 1]) else: print(p_L[idx - 1])