#include <bits/stdc++.h>

#define int long long
#define pb push_back

using namespace std;

int sum(int x){
    int ans = 0;
    while(x){
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

int f(int x){
    int x1 = x, s1 = 0, s2 = 0, cnt = 0;
    while(x1){
        s1 += x1 % 10;
        x1 /= 10;
    }
    x1 = x;
    for(int i = 2; i * i <= x; ++i){
        if(x1 % i == 0){
            while(x1 % i == 0){
                s2 += sum(i);
                x1 /= i;
                ++cnt;
            }
        }
    }
    if(x1 != 1){
        ++cnt;
        s2 += sum(x1);
    }
    if(cnt > 1 && s1 == s2) {
//        cout << s1 << endl;;
        return 1;

    }
    return 0;
}

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n, j;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> j;
        int k = j + 1;
        while(!f(k)) {
            ++k;
        }
        cout << k << " ";
    }
    return 0;
}
