import java.io.BufferedReader;
import java.io.FileReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {

	/**
	 * @param args
	 * @throws Exception 
	 */
	
	public static BigInteger NOD( BigInteger a, BigInteger b )
	{
		BigInteger  p;
		
		if ( b.compareTo( a) > 0 )
		{
			p = a;
			a = b;
			b = p;
		}
		
		while ( b.compareTo( BigInteger.ZERO ) >0)
		{
			p = b;
			b = a.mod(b);
			a = p;
		}
		
		return a;
	}
	public static void main(String[] args) throws Exception {
		BufferedReader in=new BufferedReader(new FileReader("Numbers.in"));
		int t=Integer.parseInt(in.readLine());
		for (int k = 0; k < t; k++) {
			StringTokenizer st=new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken());
			st=new StringTokenizer(in.readLine());
			BigInteger nod;
			
			//int x1 = Integer.parseInt(st.nextToken());
//			BigInteger multy=new BigInteger( st.nextToken() );
			BigInteger nok;
			nok=new BigInteger(st.nextToken());
			nod=nok;
			for(int i =1; i<n;i++)
			{
				
				BigInteger x = new BigInteger( st.nextToken() );
				nod = NOD(nod,x);
				nok = x.multiply(nok).divide(NOD(nok,x));		
				
				
			}
			
			//nok = nok.subtract(nok.divide(new BigInteger(m+"")).multiply(new BigInteger(m+"")));
			//System.out.print(nod + " ");
			System.out.println(nod + " " + nok.mod(new BigInteger(m+"")));
									
			//System.out.println((Math.abs(x2-x1)/k2)+1);
			int a =0;
			a++;
		}
	}
}
