import java.io.*;
import java.math.*;
import java.lang.*;


public class num {
	public static BigInteger gcd(BigInteger a,BigInteger b)
	{
		if (a.compareTo(BigInteger.ZERO)==0) return b;
		if (b.compareTo(BigInteger.ZERO)==0) return a;
		return gcd(b,a.mod(b));
	}
	
	public static BigInteger nok(BigInteger a,BigInteger b) {
		BigInteger q=gcd(a,b);
		return a.multiply(b).divide(q);
	}
	
	public static void main() throws FileNotFoundException,IOException
	{
		StreamTokenizer st=new StreamTokenizer(new FileReader("NUMBERS.IN"));
		int t;
		t=st.nextToken();
		for (int q=0;q<t;q++)
		{
			int n;
			Integer w,m;
			String a;
			BigInteger a1,a2,tmp;
			a1=BigInteger.ZERO;
			n=st.nextToken();
			m=new Integer(st.nextToken());
			w=new Integer(st.nextToken());
			a1=new BigInteger(w.toString());
			a2=new BigInteger(w.toString());
			for (int i=1;i<n;i++)
			{
				w=new Integer(st.nextToken());
				tmp=new BigInteger(w.toString());
				a1=gcd(a1,tmp);
				a2=nok(a2,tmp);
			}
			System.out.print(a1);
			System.out.print(" ");
			System.out.println(a2.mod(new BigInteger(m.toString())));
		}
	}
}
