#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 100;
vector<long long> vec, a, b;
long long cnt[N];
long long t, n;
bool check(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) {
      b.push_back(i);
      b.push_back(n / i);
      if (i == n / i) b.pop_back();
    }
  sort(b.begin(), b.end());
  return a == b;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      a.push_back(x);
    }
    sort(a.begin(), a.end());
    long long res = a[0] * a.back();
    cout << (check(res) ? res : -1) << '\n';
    for (auto x : vec) cnt[x] = 0;
    vec.clear();
    a.clear();
    b.clear();
  }
}
