#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)
{
	return ((a*b)/gcd(a,b));
}

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