program peti;
var
i,j,t:int32;
a,b:int64;
begin
readln(t);
for i:=1 to t do
begin
readln(a,b);
for j:= 1 to trunc(sqrt(a)) do
begin
if (a mod j=0) and (j*(a mod j)=b) then
begin
writeln(j,' ',a);
break;
end;
end;	
end;
end.