#include <bits/stdc++.h>
using namespace std;
bool isP(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
int Pp(int N)
{

    if (N <= 1)
        return 2;

    int prime = N;
    bool found = false;

    while (!found) {
        prime++;

        if (isP(prime))
            found = true;
    }

    return prime;
}


int main()
{
    long int t;
    cin>>t;
    while(t--)
    {
        int d;
        cin>>d;
        if(d==1)
        {
            cout<<6<<"\n";
            continue;
        }
        int a=1+d;
        if(!isP(a))
        {
            a=Pp(a);
        }
        int c=a+d;
        if(!isP(c))
        {
            c=Pp(c);
        }
        int ans=a*c;
        cout<<ans<<"\n";
    }
}
