#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 55555;
int n;
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> a;
    for (int i = 1; i <= n; i++) {
      long long x;
      cin >> x;
      a.push_back(x);
    }
    sort(a.begin(), a.end());
    long long ans = a[0] * a.back();
    vector<long long> tmp;
    for (long long i = 2; i * i <= ans; i++) {
      if (ans % i == 0) {
        tmp.push_back(i);
        if (i * i != ans) tmp.push_back(ans / i);
      }
    }
    sort(tmp.begin(), tmp.end());
    if (a != tmp)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
