 Function MinDiv (b:Longint):Longint;
 Var
 i,res:Longint;
 Begin
res:=b;
i:=2;
 For i:=2 to Round(sqrt(b*1.0))+1 do begin

 if ((b mod i) = 0) and (res=b) then res:=i;

 end;
 MinDiv:=res;
 end;



  Function SumNum (b:Longint):Longint;
   Var
   k:Longint;
    begin
	k:=0;
    While b <> 0 do
      begin
          k:=k+(b mod 10);
          b:=b div 10;
      end;
       SumNum:=k;
    end;




  function SumPro(a: Longint):Longint;
  Var
   s,i,res:Longint;
  Begin

  s:=0;
  If MinDiv(a)<>a then begin
      while (a<>1) do    begin
  res:=MinDiv(a);
       s:=s+SumNum(res);
       a:=a div res;

       end; end;
SumPro:=s;
  end;

var
i,j,t:Longint;
n,a:Longint;
begin
read(n);
 For i := 1 to n do  begin
    read(a);
      t:=a+1;
      while (SumPro(t) <> SumNum(t)) do
      t:=t+1;
            write(t,' ');

            end;

            end.

