#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	ifstream in("NUMBERS.IN");

	int n;
	in>>n;
	while(n--)
	{
		int N,M;
		in>>N>>M;

		vector<int>v(N);
		for(int i=0;i<N;++i)
			in>>v[i];
		
		vector<int>::iterator min;
		min = min_element(v.begin(),v.end());

		vector<int> mnod;
		for(int i=1;i<=*min;++i)
		{
			if(*min%i==0) mnod.push_back(i);
		}

		int NOD=1;
		
		for(int i=0;i<mnod.size();++i)
		{
			int k=0;
			for(int j=0;j<N;++j)
			{
				if(v[j]%mnod[i]!=0)
				{
					break;
				}
				else
					k++;
			}
			if(k==v.size() && mnod[i]>NOD)
			{
				NOD=mnod[i];
			}
		}
		cout<<NOD<<" ";

		long long NOK=1;
		vector<int>::iterator max;
		max = max_element(v.begin(),v.end());
		bool fl=false;
		long long K=1;
		NOK=*max;
		while(fl==false)
		{
			NOK=*max*K;
			int k=0;
			for(int i=0;i<v.size();++i)
			{
				if(NOK%v[i]==0)
					k++;
				else
					break;
			}
			K++;
			if(k==v.size())
				fl=true;
		}
		NOK=NOK%M;
		cout<<NOK<<endl;
	}
	return 0;
}