#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve()
{
    ll d,ans,i,j,ans2;
    cin>>d;
    for(i=d+1;;i++)
    {
        ll f=0;
        for(j=2;j*j<=i;j++)
        {
            if(i%j==0)
            {
                f=1;
                break;
            }
          
        }
          if(f==0)
          {
              ans=i;
            break;
          }
    }
    for(i=ans+d;;i++)
    {
        ll f=0;
        for(j=2;j*j<=i;j++)
        {
            
            if(i%j==0)
            {
                f=1;
                break;
            }
        }
        if(f==0)
        {
            ans2=i;
            break;
        }
    }
    cout<<min(ans*ans*ans,ans*ans2)<<endl;
}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}