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

long long gcd(long long a, long long b) {
	while(a > 0) {
		a^=b^=a^=b%=a;
	}
	return b;
}
//long long a[1000003], b[1000003];
int main() {
	ifstream I("NUMBERS.IN");
	int t;
	long long n, m;
	for (I >> t; t--; ){
		long long a, b, x, y;
		I >> n >> m;
		if (n == 1){
			I >> x;
			cout << x << " " << x << "\n";
		}
		else{
			I >> y;
			a = y;
			b = y;
			//cout << a << " " << b << " is ";
			for (; n-- > 1; ){
				x = y;
				I >> y;// cout << x << " " << y << " ";
				a = gcd(a, y);// cout << a << " =  ";
				b = b * y / gcd(x, y) % m;
			}
			cout << a << " " << b % m << "\n";
			//cout << 454 * 1374 * 466 * 1434 / 16;
		}
	}
	return 0;
}