#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int maxn = 2e5 + 7;
vector<ll> a, b;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      int t;
      scanf("%d", &t);
      a.push_back(t);
    }
    sort(a.begin(), a.end());
    ll ans = a[0] * a[n - 1];
    for (ll i = 2; i * i <= ans; ++i) {
      if (ans % i == 0) {
        b.push_back(i);
        if (i * i != ans) b.push_back(ans / i);
      }
    }
    sort(b.begin(), b.end());
    if (a == b)
      printf("%lld\n", ans);
    else
      printf("-1\n");
    a.clear();
    b.clear();
  }
  return 0;
}
