#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long ans = 1ll * a[0] * a[n - 1];
    vector<long long> mt;
    for (int i = 2; 1ll * i * i <= ans; i++) {
      if (ans % i == 0) {
        mt.emplace_back(i);
        if (ans / i != i) {
          mt.emplace_back(ans / i);
        }
      }
    }
    sort(mt.begin(), mt.end());
    if (mt == a) {
      cout << ans;
    } else {
      cout << "-1";
    }
    cout << "\n";
  }
  return 0;
}
