///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%lld",&a)
#define sf2(a,b) scanf("%lld %lld",&a,&b)
#define sf3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define timesave ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
//const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
//const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
#define SIZE 31663
long visit[SIZE],k;
long prime[100000];
void sieve()
{
long i,j;
for(i=3; i<=sqrt(SIZE); i++)
{
if(visit[i]==0)
{
for(j=2*i; j<=SIZE; j+=i)
visit[j]=1;
}
}
visit[0]=visit[1]=1;
k=0;
for(i=0; i<=SIZE; i++)
{
if(visit[i]==0)
prime[k++]=i;
}
}
long chk_prime(long number)
{
if(number==2)
return 1;
if(number%2==0)
return 0;
for(long ii=3; ii<=sqrt(number); ii+=2)
{
if(number%ii==0)
{
return 0;
}
}
return 1;
}
long sum_of_digit(long number)
{
long ans=0;
while(number!=0)
{
ans+=number%10;
number/=10;
}
return ans;
}
long factor(long number)
{
long ans=0,i,sum1=0;
for(i=0; prime[i]*prime[i]<=number; i++)
{
sum1=0;
if(number%prime[i]==0)
{
while(number%prime[i]==0)
{
sum1+=sum_of_digit(prime[i]);
number/=prime[i];
}
}
//cout<<sum1<<endl;
ans+=sum1;
}
if(number!=1)
ans+=sum_of_digit(number);
return ans;
}
main()
{
timesave;
sieve();
long ts;
cin>>ts;
while(ts--)
{
long i,n,x,sod=0,pf=0;
cin>>n;
for(i=n+1;i<=2e9; i++)
{
x=chk_prime(i);
if(x==0) ///x jodi prime na hoi tahole kaj korbe
{
sod=sum_of_digit(i);
pf=factor(i);
if(sod==pf)
{
cout<<i<<endl;
break;
}
}
}
}
}