#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

ll n, x;

ll get_sum(ll x)
{
    ll res = 0;
    while (x > 0)
    {
        res += x%10;
        x /= 10;
    }
    return res;
}

bool is_prime(ll x)
{
    if (x == 1)
        return 0;
    for (ll i = 2; i*i <= x; i++)
        if (x % i == 0)
            return 0;
    return 1;
}

bool is_smith(ll x)
{   //cout <<1 <<endl;
    if (is_prime(x))
        return 0;
    if (x == 1)
        return 1;
    ll p = 2;
    ll a = 0, b = get_sum(x);
    //cout << 1 << endl;
    while (x > 1)
    {
       while (x % p == 0)
       {
           a += get_sum(p);
           //cout << p << endl;
           x /= p;
       }
       if (x == 1 || is_prime(x))
        break;
        p++;
       while (x % p != 0)
            p++;
    }
    if (is_prime(x))
        a += get_sum(x);
    if (a == b)
        return 1;
    else
        return 0;
}

signed main()
{

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        while (1)
        {
            x++;
            if (is_smith(x))
            {
                cout << x << ' ';
                break;
            }
        }
    }
    return 0;
}
