#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, mx = 0, mn = 1000000;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
    mn = min(mn, a[i]);
  }
  long long int x = mx * mn;
  vector<long long int> d;
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      d.push_back(i);
      if (i != x / i) {
        d.push_back(x / i);
      }
    }
  }
  if (d.size() != n) {
    cout << -1 << endl;
    return;
  }
  sort(a.begin(), a.end());
  sort(d.begin(), d.end());
  for (long long int i = 0; i < n; i++) {
    if (a[i] != d[i]) {
      cout << -1 << endl;
      return;
    }
  }
  cout << x << endl;
  return;
}
int main() {
  long long int q;
  cin >> q;
  while (q--) solve();
}
