#include <bits/stdc++.h>
//#include<string>
using namespace std;
bool is_p(int a)
{
  for(int i=2;i*i<=a;++i)
  {
    if(a%i==0)
    return false;
  }
  return true;
}
int  main()
{
  int t;
  cin>>t;
  while(t--)
   {
    int d;
    cin>>d;
    if(d==1)
    {cout<<"6\n";
    continue;}

    long long ans=1;
    int c=0;
    int num=1;
    num=num+d;
    while(c<2)
    {
      
      if(is_p(num))
      {
        ++c;
        ans=ans*num;
        //cout<<num<<'\n';
        num+=d;
      }
      else
      {
        ++num;
      }
      
    }
    cout<<ans<<'\n';
   }
   
  }
  
    


