#include <stdio.h>
#include <vector>
#include <cstdlib>
using namespace std;
const int M = 1e5;
int L;
vector<long long> primes;
long long Mul(long long a, long long n, long long m) {
long long r = 0;
while (n) {
if (n % 2 == 1)
r = (r + a) % m;
a = (a + a) % m;
n /= 2;
}
return r;
}
long long Pow(long long a, long long n, long long m) {
long long r = 1;
while (n) {
if (n % 2 == 1)
r = Mul(r, a, m);
a = Mul(a, a, m);
n /= 2;
}
return r;
}
bool fermat(long long n, int iter) {
if (n == 1)
return false;
if (n <= 1e10) {
for (int k = 0; k < L; k++) {
if (n == primes[k])
return true;
if (n % primes[k] == 0)
return false;
}
}
for (int k = 0 ; k < iter; k++) {
long long a = 1 + rand() % (n-1); // 1 <= a <= n-1
if (Pow(a, n-1, n) != 1)
return false;
}
return true;
}
int main() {
bool* A = (bool*) calloc(M+1, sizeof(bool));
for (int k = 2; k <= M; k++)
if (!A[k]) {
primes.push_back(k);
if (k * 1ll * k <= M)
for (int j = k*k; j <= M; j += k)
A[j] = true;
}
L = primes.size();
long long n;
int t;
scanf("%d", &t);
for (int k = 0; k < t; k++) {
scanf("%lld", &n);
if (fermat(n,3))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjc3RkbGliPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE0gPSAxZTU7CmludCBMOwp2ZWN0b3I8bG9uZyBsb25nPiBwcmltZXM7Cgpsb25nIGxvbmcgTXVsKGxvbmcgbG9uZyBhLCBsb25nIGxvbmcgbiwgbG9uZyBsb25nIG0pIHsKCWxvbmcgbG9uZyByID0gMDsKCXdoaWxlIChuKSB7CgkJaWYgKG4gJSAyID09IDEpCgkJCXIgPSAociArIGEpICUgbTsKCQlhID0gKGEgKyBhKSAlIG07CgkJbiAvPSAyOwoJfQoJcmV0dXJuIHI7Cn0KCmxvbmcgbG9uZyBQb3cobG9uZyBsb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