#include <iostream>
#include <vector>

typedef long long LL;

LL sum(LL n)
{
  LL r = 0;
  for (;n;r += n % 10, n /= 10);
  return r;
}

LL fact(LL n)
{
   if (n < 4) return 4;
   LL k = 2;
   LL s = 0, flag = 123456;
   do
   {
      while (n % k == 0)
      {
        n /= k;
        s += sum(k);
        flag = 0;
      }
      k++;
      if (k * 1LL * k > n && n != 1)
      {
         s += sum(n);
         break;
      }
   } while (n!=1);
   return s + flag;
}

LL next(LL n)
{
  do 
  {
    n++;
  } while (sum(n) != fact(n));
  return n;
}

int main()
{
  LL n, x;
  std::cin >> n;
  for (int i = 0; i < n; i++)
  {
     std::cin >> x;
     std::cout << next(x) << " ";
  }
  std::cout << std::endl;
  return 0;
}

