#include <bits/stdc++.h>
using namespace std;
int main() {
  int amount_test;
  cin >> amount_test;
  for (int test = 0; test < amount_test; ++test) {
    int n;
    cin >> n;
    vector<long long> div;
    for (int i = 0; i < n; ++i) {
      int d;
      cin >> d;
      div.push_back(d);
    }
    sort(div.begin(), div.end());
    long long result = div.back() * div[0];
    vector<long long> all_div;
    for (long long i = 2; i <= sqrt(result); ++i) {
      if (result % i == 0) {
        all_div.push_back(i);
        if (i != sqrt(result)) all_div.push_back(result / i);
      }
    }
    sort(all_div.begin(), all_div.end());
    bool ok = true;
    if (all_div.size() != div.size()) {
      ok = false;
    } else {
      for (int i = 0; i < n; ++i) {
        if (div[i] != all_div[i]) ok = false;
      }
    }
    if (ok)
      cout << result << "\n";
    else
      cout << -1 << "\n";
  }
}
