#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> d(n);
    for (int i = 0; i < n; i++) {
      cin >> d[i];
    }
    sort(d.begin(), d.end());
    int Min = d[0];
    int Max = d[n - 1];
    long long num = 1LL * Min * Max;
    vector<long long> dd;
    for (int i = 2; 1LL * i * i <= num; i++) {
      if (num % i == 0) {
        dd.push_back(i);
        if (i != num / i) {
          dd.push_back(num / i);
        }
      }
    }
    sort(dd.begin(), dd.end());
    if (dd == d) {
      cout << num << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
  return 0;
}
