#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std;
#define LL long long
#define F(i,a,b) for (int i=(a),_##i=(b); i<=_##i; i++)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define rep(i,a,b) for (int i=(a),_##i=(b); i<=_##i; i++)
#define rek(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define Cpy(a,b) memcpy(a,b,sizeof(b))
const int P=sqrt(1e9);
int prime[P];
bool is_prm[P+5];
bool check(LL x){
for(int i=1;i<=prime[0]&&prime[i]*prime[i]<=x;++i)
if(x%prime[i]==0&&(x/=prime[i])%prime[i]==0)
return 0;
return 1;
}
inline LL ab(LL x)
{
return x<0?-x:x;
}
int t;
LL x;
const int eps=1e-8;
int main()
{
//欧拉筛
for(int i=2;i<=P;++i){
if(!is_prm[i])prime[++prime[0]]=i;
for(int j=1;j<=prime[0]&&i*prime[j]<=P;++j){
is_prm[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
//freopen("in.txt","r",stdin);
for(scanf("%d",&t);t--;)
{
scanf("%I64d",&x);
for(int yy1=sqrt(x),yy2=yy1+1;;)
{
//printf("%lf\n",sqrt(x));
//printf("yy1=%I64d y1=%I64d\n",yy1,y1);
//printf("%I64d\n",yy1);
if(yy1>1&&(x-(LL)yy1*yy1<(LL)yy2*yy2-x))
{
if(!check(yy1)) goto f;else {
printf("%I64d\n",(x-(LL)yy1*yy1));goto flag;
}
f:yy1--;
}
///yy2=(LL)sqrt(y2);//printf("yy2=%I64d y2=%I64d\n",yy2,y2);
else
{
if(!check(yy2)) goto g;else {
printf("%I64d\n",((LL)yy2*yy2-x));goto flag;
}
g:yy2++;
}
}
flag:;
}
return 0;
}