//
// main.cpp
// Sieve of Eratosthenes
//
// Created by Himanshu on 18/08/21.
//
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
typedef unsigned long long ll;
int sieve[2000000] = {0};
void solve() {
ll i,j;
// marking all evens as non-prime
// if: sieve[i] = 0, it is prime
// if sieve[i] = 1, it is composite
for (i=4; i<=1000001; i+=2) {
sieve[i] = 1;
}
// Checking all odd numbers
for (i=3; i<=1000001; i+=2) {
for (j=i*i; j<=1000001; j+=i) {
sieve[j] = 1;
}
}
}
// Utility function to check if a particular
// number is prime
bool isprime(ll n) {
ll i,root;
root = (ll)sqrt(n) + 1;
for (i=2; i<=root; i++) {
if (n%i == 0) {
return false;
}
}
return true;
}
int main() {
ll T, n, sol, root, tp;
scanf("%llu",&T);
solve();
while (T--) {
scanf("%llu",&n);
root = (ll)sqrt(n) + 1;
sol = n;
for (ll i=2; i<=root; i++) {
if (n%i == 0) {
tp = n/i;
if (sieve[i] == 0) {
sol = i;
}
// selecting the larger prime between tp and i
if (tp > i) {
if (tp <= 1000000) {
if (sieve[tp] == 0) {
sol = tp;
break;
}
} else if (isprime(tp)) {
sol = tp;
break;
}
}
}
}
printf("%llu\n",sol);
}
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBTaWV2ZSBvZiBFcmF0b3N0aGVuZXMKLy8KLy8gIENyZWF0ZWQgYnkgSGltYW5zaHUgb24gMTgvMDgvMjEuCi8vCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyBsbDsKaW50IHNpZXZlWzIwMDAwMDBdID0gezB9OwoKdm9pZCBzb2x2ZSgpIHsKICAgIGxsIGksajsKCiAgICAvLyBtYXJraW5nIGFsbCBldmVucyBhcyBub24tcHJpbWUKICAgIC8vIGlmOiBzaWV2ZVtpXSA9IDAsIGl0IGlzIHByaW1lCiAgICAvLyBpZiBzaWV2ZVtpXSA9IDEsIGl0IGlzIGNvbXBvc2l0ZQogICAgZm9yIChpPTQ7IGk8PTEwMDAwMDE7IGkrPTIpIHsKICAgICAgICBzaWV2ZVtpXSA9IDE7CiAgICB9CgogICAgLy8gQ2hlY2tpbmcgYWxsIG9kZCBudW1iZXJzCiAgICBmb3IgKGk9MzsgaTw9MTAwMDAwMTsgaSs9MikgewogICAgICAgIGZvciAoaj1pKmk7IGo8PTEwMDAwMDE7IGorPWkpIHsKICAgICAgICAgICAgc2lldmVbal0gPSAxOwogICAgICAgIH0KICAgIH0KICAgIAp9CgovLyBVdGlsaXR5IGZ1bmN0aW9uIHRvIGNoZWNrIGlmIGEgcGFydGljdWxhcgovLyBudW1iZXIgaXMgcHJpbWUKYm9vbCBpc3ByaW1lKGxsIG4pIHsKICAgIGxsIGkscm9vdDsKICAgIHJvb3QgPSAobGwpc3FydChuKSArIDE7CiAgICAKICAgIGZvciAoaT0yOyBpPD1yb290OyBpKyspIHsKICAgICAgICBpZiAobiVpID09IDApIHsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgIH0KICAgIAogICAgcmV0dXJuIHRydWU7Cn0KCgppbnQgbWFpbigpIHsKICAgIAogICAgbGwgVCwgbiwgc29sLCByb290LCB0cDsKICAgIHNjYW5mKCIlbGx1IiwmVCk7CiAgICAKICAgIHNvbHZlKCk7CiAgICAKICAgIHdoaWxlIChULS0pIHsKICAgICAgICBzY2FuZigiJWxsdSIsJm4pOwogICAgICAgIHJvb3QgPSAobGwpc3FydChuKSArIDE7CiAgICAgICAgc29sID0gbjsKICAgICAgICAgIAogICAgICAgIGZvciAobGwgaT0yOyBpPD1yb290OyBpKyspIHsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmIChuJWkgPT0gMCkgewogICAgICAgICAgICAgICAgdHAgPSBuL2k7CiAgICAgICAgICAgICAgICBpZiAoc2lldmVbaV0gPT0gMCkgewogICAgICAgICAgICAgICAgICBzb2wgPSBpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIC8vIHNlbGVjdGluZyB0aGUgbGFyZ2VyIHByaW1lIGJldHdlZW4gdHAgYW5kIGkKICAgICAgICAgICAgICAgIGlmICh0cCA+IGkpIHsKICAgICAgICAgICAgICAgICAgICBpZiAodHAgPD0gMTAwMDAwMCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoc2lldmVbdHBdID09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNvbCA9IHRwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGlzcHJpbWUodHApKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNvbCA9IHRwOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHByaW50ZigiJWxsdVxuIixzb2wpOwogICAgfQoKICAgIHJldHVybiAwOwp9