import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
public static BigInteger gcd1 (BigInteger a,BigInteger b){
		while(a.compareTo(BigInteger.ZERO)!=0 && b.compareTo(BigInteger.ZERO)!=0){
			if(a.compareTo(b)>0)
				a=a.subtract(b);
			else
				b=b.subtract(a);
		}
		return a.add(b);
	}
public static int gcd2 (int a,int b){
	while(a>0 && b>0){
		if(a>b)
			a-=b;
		else
			b-=a;
	}
	return (a+b);
}
public static void main (String []args ) throws FileNotFoundException
{
	Scanner sc = new Scanner (new File("NUMBERS.IN"));
	
	int t,n,m,a[]=new int [1001],nd;
	BigInteger nk = new BigInteger ("0");
	
	
	t = sc.nextInt();
	for(int i=0;i<t;i++){
		n =sc.nextInt();
		m=sc.nextInt();
		for(int j=0;j<n;j++)
			a[j]=sc.nextInt();
		
		nk=new BigInteger (Integer.toString(a[0]));
		nd=a[0];
		for(int j=1;j<n;j++){
			nd = gcd2 (nd,a[j]);
		}
		for(int j=1;j<n;j++){
			BigInteger nk2 = BigInteger.ZERO;
			nk2 = nk.multiply(new BigInteger(Integer.toString(a[j])));
			nk=nk2.divide(gcd1(nk,new BigInteger(Integer.toString(a[j]))));
		}
		System.out.println(nd+" "+nk.mod(new BigInteger(Integer.toString(m))));
	}
	
	
}
}
