https://www.acmicpc.net/problem/2702
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
for(int i=0;i<n;i++){
int a=s.nextInt();
int b=s.nextInt();
int min=0;
int max=0;
for(int j=1;;j++){
if(a%j==0 && b%j==0) max=j;
if(j%a==0 && j%b==0){
min=j;
break;
}
}
System.out.format("%d %d\n",min,max);
}
}
}