#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

__int64 gcd (__int64 a, __int64 b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

__int64 lcm (__int64 a, __int64 b) {
	return a / gcd (a, b) * b;
}

int main()
{
	freopen("NUMBERS.IN", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		vector<__int64> arr(n);
		for (int i = 0; i < n; ++i)
			cin >> arr[i];
		__int64 lgcd = arr[0], llcm = arr[0];
		for (int i = 1; i < n; ++i)  {
			lgcd = gcd(arr[i], lgcd);
			llcm = lcm(arr[i], llcm) % m;
		}
		cout << lgcd << " " << llcm << endl;

	}
	return 0;
}