#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, ans, x, t = 0;
    bool flag = true;
    cin >> n;
    vector<long long int> a;
    set<long long int> b;
    for (int i = 0; i < n; i++) {
      cin >> x;
      a.push_back(x);
    }
    sort(a.begin(), a.end());
    ans = a[0] * a[n - 1];
    for (int i = 2; i < sqrt(ans) + 1; i++) {
      if (ans % i == 0) {
        b.insert(i);
        b.insert(ans / i);
      }
    }
    if (b.size() != a.size()) flag = false;
    for (auto it : b) {
      if (it != a[t]) {
        flag = false;
        break;
      }
      t++;
    }
    if (flag)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
