#include"stdio.h"
int max(int a,int b)
{
int q,w;
if(a>b)
{q=a;
w=b;}
else
{q=b;
w=a;}
while(1)
{if(q%w==0)
{return q;
break;
}
else
q=q+q;
}
}
int min(int a,int b)
{
int o,p;
if(a<b)
o=a;
else
o=b;
for(o;o>=1;o--)
if(a%o==0&&b%o==0)
{return o;
break;}
}
main()
{
int a,b,x,j,m,n;
scanf("%d",&n);
for(j=1;j<=n;j++)
{scanf("%d%d",&a,&b);
m=max(a,b);
x=min(a,b);
printf("%d %d\n",x,m);}
}