#include <iostream>

using namespace std;

int main(){
	freopen ("NUMBERS.IN","r",stdin);

	int am_tests;
	cin>>am_tests;

	for (int i=0;i<am_tests;i++){
		__int64 n,mod,A[1001];
		cin>>n>>mod;
		
		for (int j=0;j<n;j++)
			cin>>A[j];
		
		__int64 max = A[0];
		for (int j=0; j<n; j++){
			if (max < A[j]) max = A[j];
		}
		__int64 min;
		for (int j=1; j<max; j++){
			bool fl = true;
			for(int z=0; z<n; z++){
				if (A[z]%j != 0) {fl = false; break;}; 
			}
			if (fl){min=j;};
		}
		cout << min << " ";
		for (int j=1;;j++){
			bool fl = true;
			__int64 rez=j*max;
			for(int z = 0; z<n; z++){
				if (rez%A[z] != 0) {fl = false; break;};
			}
			if (fl) {min = rez; break;};
		}


		/*cout << min << " ";
		for (int j=max; j<=mod; j++){
			bool fl = true;
			for(int z = 0; z<n; z++){
				if (j%A[z] != 0) {fl = false; break;};
			}
			if (fl == true) {min=j; break;};
		}*/
		cout << min%mod << endl;

		

	}
	return 0;
}