import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Numbers_dt
{
	public static void main(String[] args) throws Exception
    {
		new Numbers_dt().run();
    }
	
	StreamTokenizer in;
	PrintWriter out;
	
	int nextInt() throws IOException
    {
		in.nextToken();
        return (int)in.nval;
    }
	
	int gcd(int a, int b)
	{
		while(b != 0)
		{
			int tmp = b;
			b = a%b;
			a = tmp; 
		}
		return a;		
	}
	
	BigInteger lcm(BigInteger a, BigInteger b)
	{
		BigInteger d = a.gcd(b);
		return a.multiply(b).divide(d);
	}
	
	void run() throws Exception
	{
		in = new StreamTokenizer(new BufferedReader(new FileReader("numbers.in")));
		out = new PrintWriter(new OutputStreamWriter(System.out));
		//out = new PrintWriter(new FileWriter("numbers.out"));
		
		int test = nextInt();

		//int values[] = new int[1024];
		
		for(int t=0; t<test; t++)
		{
			int n = nextInt(), m = nextInt();
			
			assert(n >=1 && n<= 1000);
			assert(m >=1 && n<= 1000000000);
			
			int values[] = new int[n];
			
			for(int i=0; i<n; i++)
			{
				values[i] = nextInt();				
			}
			
		
			int res1 = values[n-1];
			BigInteger res2 = BigInteger.valueOf(values[n-1]);
			for(int i=n-2; i>-1; i--)
			{
				res1 = gcd(values[i], res1);
				res2 =  lcm(res2, BigInteger.valueOf(values[i]));
			}			
			
			out.println(res1 + " " + res2.mod(BigInteger.valueOf(m)));
			
		}
		out.close();
	}

}
