#include <iostream>
#include <fstream>
using namespace std;

__int64 nod(__int64 a,__int64 b)
{
	if (a==0) return b;
	if (b==0) return a;
	return nod(b,a%b);
}

__int64 nok(__int64 a,__int64 b,__int64 m)
{
	__int64 gcd=nod(a,b);
	a/=gcd;
	return ((a%m)*(b%m));
}

int main()
{
	ifstream in("NUMBERS.IN");
	int t;
	in>>t;
	for (int q=0;q<t;q++)
	{
		int n;
		__int64 m,a1,a2,tmp;
		in>>n>>m;
		in>>a1;
		a2=a1;
		for (int i=1;i<n;i++)
		{
			in>>tmp;
			a1=nod(a1,tmp);
			a2=nok(a2,tmp,m);
			//a2%=m;
		}
		cout<<a1<<" "<<a2<<endl;
	}
	return 0;
}