#include <iostream>
#include <fstream>
using namespace std;

long long nod(long long a,long long b)
{
	long long c;
	if (a<b)
	{		
		c=a;		a=b;
		b=c;
	}
	
	while(b!=0)
	{
		a=a%b;		
		if (a<b)
		{
			c=a;	a=b;
			b=c;
		}
	}
	return a;
}

long long NOK(long long a, long long b)
{
	return a*b/nod(a,b);
}


int main()
{
	ifstream F("NUMBERS.IN",ios::in);
	int T,N;
	long long x,y,M,x1;
		
	F>>T;
	for (int j=0; j< T; j++)
	{
		F>>N>>M;
		F>>x; x1 = x;
		for (int i=0; i<N-1; i++)
		{
			F>>y;
			x = nod(x,y);
			x1 = NOK(x1,y);			
		}
		x1 = x1 % M;
		cout<<x<<" "<<x1<<endl;
	}
	
	F.close();	
	return 0;
}

