#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T x) {
  cout << x << endl;
}
template <typename T1, typename T2>
void print2(T1 x, T2 y) {
  cout << x << " " << y << endl;
}
template <typename T1, typename T2, typename T3>
void print3(T1 x, T2 y, T3 z) {
  cout << x << " " << y << " " << z << endl;
}
void chandan1() {
  int y = 1;
  return;
}
void chandan2() {
  for (long long int i = 0; i < 10; i++) {
    long long int x = 1;
  }
  return (chandan1());
}
vector<long long int> divisors(long long int n) {
  vector<long long int> div;
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        div.emplace_back(i);
      else {
        div.emplace_back(i);
        div.emplace_back(n / i);
      }
    }
  }
  sort(div.begin(), div.end());
  return div;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  chandan2();
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> a;
    for (long long int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      a.emplace_back(x);
    };
    sort(a.begin(), a.end());
    long long int val = a[0] * a[n - 1];
    vector<long long int> divi = divisors(val);
    if (divi == a)
      print(val);
    else
      print(-1);
  }
  return 0;
}
