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