#include <iostream>
using namespace std;

long long int gcd(int a, int b)
{
	if(a%b == 0)
		return b;
	else
		return gcd(b, a%b);
}

long long int nok(int a, int b, int M)
{
	return ((a%M*b%M)/gcd(a,b)%M);
}

int main()
{
	freopen("numbers.in","r",stdin);
	long long int T,gcd1,nok1,N,a,M,b;
	cin >> T;
	for(int j = 0; j < T; j++)
	{
		cin >> N >> M;
		cin >> a;
		gcd1 = a;
		nok1 = a % M;
		if(N == 1)
		{
			cout << gcd1 << " " << nok1 << endl;
			continue;
		}
		else
		{
			for(int i = 0; i < N-1; i++)
			{
				cin >> b;
				if(b == a)
					continue;
				gcd1 = gcd(gcd1,b);
				nok1 = nok(nok1,b,M);
				a = b;
			}
			cout << gcd1 << " " << nok1%M << endl;
		}
	}
	return 0;
}