#include <iostream>

using namespace std;

int eno(int a,int 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);
	int t,n,a[1001];
	__int64 m,nk,nd;
	cin >> t;

	for (int i=0;i<t;i++)
	{
		cin >> n >> m;
		for (int j=0;j<n;j++)
			cin >> a[j];
		nd = a[0];
		for (int j=1;j<n;j++)
		{
			nd = eno(nd,a[j]);
		}
		nk = a[0];
		for (int j=1;j<n;j++)
		{
			//nk = ((nk * a[j]) / nd) % m;
			nk = ((nk * a[j]) / eno(nk,a[j])) % m;
		}
		cout << (nd % m) << " " << (nk % m) << endl;
	}

	return 0;
}