#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wsign-compare"
using namespace std;
const long long N = 1e5 + 5;
long long n, m, k = 0, t = 1, x, y, z, l, r, w, d, q, ct = 0, ans = 0, f = 0;
string s, p;
set<long long> si;
map<long long, long long> mi;
long long div_count(long long n) {
  long long ans = 0;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) ans += 2;
    if (i * i == n) ans--;
  }
  return ans;
}
signed main() {
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n];
    long long f = 0;
    for (long long i = 1; i <= n; i++) cin >> a[i - 1];
    sort(a, a + n);
    long long pro = a[0] * a[n - 1];
    for (long long i = 0; i < n; i++) {
      if ((a[i] * a[n - i - 1]) != pro) {
        f = 1;
        break;
      }
    }
    if (f || div_count(pro) != n) pro = -1;
    cout << pro << "\n";
  }
}
