#include <bits/stdc++.h>
using namespace std;
long long f(long long x) {
  int num = 0;
  for (int i = 1; 1ll * i * i <= x; i++) {
    if (x % i) continue;
    num++;
    if (1ll * i * i != x) num++;
  }
  return num;
}
long long solve(vector<int> v) {
  int n = v.size();
  long long num = 1ll * v[0] * v[n - 1];
  for (int i = 1; i < n / 2 + (n % 2); i++) {
    long long cur = 1ll * v[i] * v[n - i - 1];
    if (cur != num) return -1;
  }
  if (f(num) != n + 2) return -1;
  return num;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << solve(a) << endl;
  }
  return 0;
}
