#include <bits/stdc++.h>
using namespace std;
#define int int64_t
using vi = vector<int>;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
const int MX = 4e5 + 5;
vi p(MX);
FOR(i, 2, MX) if (!p[i]) for (int j = i; j < MX; j += i) p[j] = i;
int t; cin >> t; for (int tt = 1; tt <= t; tt++) {
int n; cin >> n;
vi a(n); for (auto& i : a) cin >> i;
int pr = -1;
FOR(i, 0, n) if (p[a[i]] == a[i]) pr = a[i];
cout << pr << endl;
if (pr == -1) {
cout << 2 << endl;
continue;
}
int good = 1;
FOR(i, 0, n) {
if (a[i] == pr) continue;
if (p[a[i]] == a[i]) good = 0;
if (a[i] % 2 and a[i] - p[a[i]] < 2 * pr) good = 0;
if (a[i] % 2 == 0 and a[i] < 2 * pr) good = 0;
}
if (good) cout << pr << endl;
else cout << -1 << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGludDY0X3QKdXNpbmcgdmkgPSB2ZWN0b3I8aW50PjsKI2RlZmluZSBGT1IoaSwgYSwgYikgZm9yIChpbnQgaSA9IChhKTsgaSA8IChiKTsgaSsrKQojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCksIHguZW5kKCkKCnNpZ25lZCBtYWluKCkgewoJaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7Cgljb25zdCBpbnQgTVggPSA0ZTUgKyA1OwoJdmkgcChNWCk7CglGT1IoaSwgMiwgTVgpIGlmICghcFtpXSkgZm9yIChpbnQgaiA9IGk7IGogPCBNWDsgaiArPSBpKSBwW2pdID0gaTsKCWludCB0OyBjaW4gPj4gdDsgZm9yIChpbnQgdHQgPSAxOyB0dCA8PSB0OyB0dCsrKSB7CgkJaW50IG47IGNpbiA+PiBuOwoJCXZpIGEobik7IGZvciAoYXV0byYgaSA6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