#include <stdio.h>
#include <iostream>

using namespace std;

long long nod (int a, int b) {
    return a == 0 ? b : nod(b%a,a);
}

long long nok (int a, int b) {
    long long nd = nod(a,b);
    return a*b/nd;
}

void solve() {
    int N,M;
    cin >> N >> M;

    int a[10000];

    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    long long nk,nd;
    nk = nd = a[0];

    for(int i = 1; i < N; i++) {
        nk = nok(nk,a[i]) % M;
        nd = nod(nd,a[i]);
    }

    cout << nd << " " << nk << endl;

}

int main()
{
    //fstream fin("SHADOOF.IN");
    freopen("NUMBERS.IN", "r",stdin);
    int n;
    cin >> n;
    //cout << nok(2,4);
    for(int ii = 0; ii < n; ++ii)
    {
        solve();
    }

    return 0;
}
