// аудитория 3-11
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

long long gcd(long long a, long long b){
    while(a && b){
        if(a>b) a%=b;
        else b%=a;
    }
    return a+b;
}

long long lcm(long long a, long long b, long long m){
    long long x = (a/gcd(a,b))*b;
    if (x%m=0)
        return x;
    else
        return x%m;
}

int main(){
    freopen("NUMBERS.IN", "r", stdin);
    int t;
    cin >> t;
    for (int k=0; k<t; k++)
    {
        int n;
        long long nod, m, nok;
        cin >> n >> m >> nod;
        nok = nod;
        for(int i=1; i<n; ++i){
            long long x;
            cin >> x;
            nod = gcd(nod, x);
            nok = lcm(nok, x, m);
        }
        cout << nod << ' ' << nok << endl;
    }
    return 0;
}
