import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.Scanner;

import sun.util.BuddhistCalendar;

public class Acm {
	//Scanner in;
	StreamTokenizer in;
	PrintWriter out;
	BigInteger ans;
	private void solve() throws IOException{
		int T;

		T = nextInt();
		while(T!=0){
			T = T-1;
			int n = nextInt();
			BigInteger M = new BigInteger( (Integer.valueOf(nextInt())).toString());
			BigInteger p = BigInteger.ONE;
			//BigInteger p2 = BigInteger.ONE;
			BigInteger g;
			g = new BigInteger( (Integer.valueOf(nextInt())).toString());
			p= p.multiply(g);

			for(int i=1;i<n;i++){
				BigInteger temp = new BigInteger( (Integer.valueOf(nextInt())).toString());
				g = gcd(g,temp);
				p = nok(p,temp);
				//out.println("_"+g+" "+p.mod(M));
			}
			
			//ans = ans.divide(new BigInteger((Integer.valueOf(n+1)).toString()));
			out.print(g);
			out.print(" ");
			out.println(p.mod(M));
			//out.println((p.divide(g)).mod(M));
		}
	}
	private BigInteger gcd(BigInteger a, BigInteger b) {
		if( b.equals(BigInteger.ZERO) )
			return a;
		else
			return gcd(b,a.mod(b));
	}
	private BigInteger nok(BigInteger a, BigInteger b) {
		return (a.multiply(b)).divide(gcd(a,b));
	}
	private int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}
	Acm() throws IOException{
		//in = new Scanner(new File("STAIRS.IN"));
		//out = new PrintWriter(System.out);
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(new FileInputStream("NUMBERS.IN"))));
		out = new PrintWriter(new OutputStreamWriter(System.out));
		solve();
		out.flush();
	}
	
	public static void main(String[] args) {
		try {
			new Acm();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
/*
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;

public class Acm {
	Scanner in;
	PrintWriter out;
	BigInteger ans;
	BigInteger d[];
	private void solve() throws IOException{
		int T,n;
		d = new BigInteger[2003];
		d[0] = BigInteger.ONE;
		d[1] = BigInteger.ONE;
		for(int i=2;i<2003;i++){
			BigInteger t = new BigInteger((Integer.valueOf(i)).toString());
			t = t.multiply(d[i-1]);
			d[i] = t;  
		}
		T = in.nextInt();
		while(T!=0){
			T = T-1;
			n = in.nextInt();
			n = n+1;
			ans = BigInteger.ONE;
			ans = ans.multiply(d[2*n]);
			ans = ans.divide(d[n]);ans = ans.divide(d[n]);
			ans = ans.divide(new BigInteger((Integer.valueOf(n+1)).toString()));
			out.println("_"+d[2*n]);out.flush();
			out.println("_"+d[n]);out.flush();
			out.println("_"+d[n]);out.flush();
			out.println(ans);
		}
	}
	Acm() throws IOException{
		in = new Scanner(new File("STAIRS.IN"));
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}
	
	public static void main(String[] args) {
		try {
			new Acm();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

 * 
 */
