#include <bits/stdc++.h>
const double pi = 2.0 * acos(0.0);
using namespace std;
vector<long long> v;
void divisors(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int t, kase = 1;
  cin >> t;
  while (t--) {
    long long n, i, j, k = 0;
    cin >> n;
    long long a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    long long ans = a[0] * a[n - 1];
    divisors(ans);
    sort(v.begin(), v.end());
    if (v.size() == n) {
      for (i = 0; i < n; i++) {
        if (a[i] != v[i]) {
          k = 1;
          break;
        }
      }
      if (k)
        cout << "-1" << endl;
      else
        cout << ans << endl;
    } else
      cout << "-1" << endl;
    v.clear();
  }
  return 0;
}
