#include <stdio.h>
#include <math.h>
int main (){
int a,b,e,f,k,t,x,y,g[100],h[100];
scanf("%d",&a);
while (a--){
scanf ("%d",&b);
t=0;
for (e=1;e<=100;e++){
k=0;
for (f=1;f<=e;f++){
if(e%f==0)
k++;
}
if(k==2){
t++;
g[t-1]=e;
}
}
for(e=0;e<t;e++){
h[e]=abs(b-g[e]);
}
for(e=0;e<t-1;e++){
for(x=0;x<t-1-e;x++){
if (h[x]>=h[x+1]){
y=h[x];
k=g[x];
h[x]=h[x+1];
g[x]=g[x+1];
h[x+1]=y;
g[x+1]=k;
}
}
}
if (h[0]==h[1]&&g[1]>g[0])
printf("%d\n",g[1]);
else
printf("%d\n",g[0]);
}
return 0;
}
#include <math.h>
int main (){
int a,b,e,f,k,t,x,y,g[100],h[100];
scanf("%d",&a);
while (a--){
scanf ("%d",&b);
t=0;
for (e=1;e<=100;e++){
k=0;
for (f=1;f<=e;f++){
if(e%f==0)
k++;
}
if(k==2){
t++;
g[t-1]=e;
}
}
for(e=0;e<t;e++){
h[e]=abs(b-g[e]);
}
for(e=0;e<t-1;e++){
for(x=0;x<t-1-e;x++){
if (h[x]>=h[x+1]){
y=h[x];
k=g[x];
h[x]=h[x+1];
g[x]=g[x+1];
h[x+1]=y;
g[x+1]=k;
}
}
}
if (h[0]==h[1]&&g[1]>g[0])
printf("%d\n",g[1]);
else
printf("%d\n",g[0]);
}
return 0;
}