#include <iostream>

using namespace std;

__int64 gcd(__int64 a,__int64 b)
{
	while (a > 0 && b > 0)
	{
		if (a > b)
			a -= b;
		else b -=a;
	}
	return (a+b);
}

int main()
{
	freopen("NUMBERS.IN","r",stdin);
	//freopen("output.txt","w",stdout);
	__int64 t,n,a[1001];
	__int64 m,nk,nd,nk2;
	cin >> t;
	__int64 q = 1000000;
	q = q*q;
	for (int i=0;i<t;i++)
	{
		cin >> n >> m;
		for (int j=0;j<n;j++)
			cin >> a[j];
		nk = a[0];
		nd = a[0];
		for (int j=1;j<n;j++)
		{
			nd = gcd(nd,a[j]);
		}
		for (int j=1;j<n;j++)
		{
			nk2 = (nk * a[j]) / gcd(nk,a[j]);
			if (nk2 > q)
			nk = nk2 % m;
			else
			nk = nk2;
		}
		cout << nd << " " << nk %m << endl;
	}

	return 0;
}