program zadatak5;

var
t,f,i,st,ll,j:integer;
a,b:int64;
tn:array[1..10000] of integer;
k:real;


{$mode objfpc}{$H+}
begin
   read(t);
   st:=0;
   for i:=1 to t do
   tn[i]:=0;

   for i:=1 to t do
       begin
         read(a,b);
         k:=sqrt(a);
         ll:=round(k);
         for  j:=2 to ll  do
                  begin
                    if (a mod j = 0) then
                    begin
                      if((a div j) xor j = b) then
                      begin
                       st:=st+1;
                       tn[st]:= (a div j);
                       st:=st+1;
                       tn[st]:=j;
                        end
                      else
                      begin
                        st:=st+1;
                        tn[st]:=-1;
                      end;

                    end ;


                  end;
       end;
   i:=1;
   while i< st+1 do
     begin
     if (tn[i]= -1 ) then
     begin
          write('-1',' ') ;
          i:=1+i;
     end
     else
     begin
     write(tn[i],' ',tn[i+1],' ');
     i:=i+2;
      end;
     end;

  end.