#include <iostream>
using namespace std;

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

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

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