#include <bits/stdc++.h>
using namespace std;
vector<long long> a, b;
int main() {
  int n, t;
  cin >> t;
  while (t--) {
    cin >> n;
    a.resize(n);
    b.clear();
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    long long val = a[0] * a.back();
    for (long long i = 2; i * i <= val; i++) {
      if (val % i == 0) {
        b.push_back(i);
        if (i != val / i) b.push_back(val / i);
      }
    }
    sort(b.begin(), b.end());
    if (a == b)
      cout << val << "\n";
    else
      cout << "-1\n";
  }
}
