#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> v(n);
    set<long long int> m;
    for (long long int i = 0; i < n; i++) {
      cin >> v[i];
      m.insert(v[i]);
    }
    sort(v.begin(), v.end());
    long long int d = v[0] * v[n - 1];
    long long int i;
    for (i = 0; i < n; i++) {
      if (d % v[i] != 0) break;
      if (m.count(d / v[i]) == 0) break;
    }
    if (i != n) {
      cout << -1 << endl;
      continue;
    }
    long long int f = 0;
    for (i = 2; i <= sqrt(d); i++) {
      if (d % i == 0) {
        if (m.count(i) == 0) {
          f = 1;
          break;
        }
        if (m.count(d / i) == 0) {
          f = 1;
          break;
        }
      }
    }
    if (f == 0)
      cout << d << endl;
    else
      cout << -1 << endl;
  }
}
