#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> divs;
    for (int i = 0; i < n; ++i) {
      long long d;
      cin >> d;
      divs.push_back(d);
    }
    sort(divs.begin(), divs.end());
    long long num = divs.front() * divs.back();
    vector<long long> foo;
    for (long long i = 2; i * i <= num; ++i) {
      if (num % i == 0) {
        foo.push_back(i);
        if (i != num / i) foo.push_back(num / i);
      }
    }
    sort(foo.begin(), foo.end());
    if (foo == divs)
      cout << num << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
