#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 1;
int sieve[N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    for (int i = 2; i * i < N; ++i) {
        if (sieve[i] == 1) {
            continue;
        }
        for (int j = 2 * i; j < N; j += i) {
            sieve[j] = 1;
        }
    }
    int t; cin >> t;
    while (t--) {
        int d; cin >> d;
        long long ans = 1;
        int aux = 1 + d;
        while (sieve[aux] == 1) {
            aux++;
        }
        ans *= aux;
        aux += d;
        while (sieve[aux] == 1) {
            aux++;
        }
        ans *= aux;
        cout << ans << '\n';
    }
    return 0;
}
