#include <iostream>
#include <math.h>

using namespace std;

long long S(long long n)
{
    long long k = n;
    long long r = 0;
    while (k != 0)
    {
        r += k%10;
        k = k/10;
    }
    return r;
}

bool simple(long long n)
{
    long long ma = sqrt(n)+1;
    long long i;
    for (i = 2;i <= ma;i++) if (n%i == 0) return false;
    return true;
}

int main()
{
    long long n,i,m,a,b;
    cin >> n;

    for (i = 1;i <= n;i++)
    {
        cin >> m;
        long long ans = m+1;
        bool flag = true;
        while (flag)
        {
            b = 0;
            a = 2;
            long long ans1 = ans;
            while (ans1 != 1)
            {
                if (ans1 % a == 0)
                {
                    ans1 = ans1/a;
                    b += S(a);
                }
                else a++;
            }
            if (b == S(ans) && !simple(ans))
            {
                if (i != n ) cout << ans << " ";
                else cout << ans;
                break;
            }
            ans++;
        }
    }
}
