#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i];
    sort(vec.begin(), vec.end());
    long long int x = vec[0] * vec[n - 1];
    vector<long long int> vec1;
    for (int i = 2; i * 1ll * i <= x; i++) {
      if (x % i == 0) {
        vec1.push_back(i);
        if (i != x / i) {
          vec1.push_back(x / i);
        }
      }
    }
    sort(vec1.begin(), vec1.end());
    if (vec == vec1) {
      cout << x << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
