#include <bits/stdc++.h>
using namespace std;
const long double pi = 2 * acos(0.0);
long long infinity = std::numeric_limits<long long>::max();
const long long mod = 998244353;
const long long MAXN = 1;
long long binary_search(long long dp[], long long n, long long p) {
  long long l, r, mid;
  l = 0;
  r = n - 1;
  while (l <= r && l >= 0 && l <= n - 1 && r >= 0 && r <= n - 1) {
    mid = (l + r) / 2;
    if (dp[mid] >= p) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return l;
}
int extended_euclid(int a, int b, int& x, int& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1, g;
  g = extended_euclid(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return g;
}
bool linear_diaphantine(int a, int b, int c, int& x, int& y, int& g) {
  int x1, y1;
  g = extended_euclid(abs(a), abs(b), x1, y1);
  if (c % g) {
    return false;
  }
  x = (c / g) * x1;
  y = (c / g) * y1;
  if (a < 0) x = -x;
  if (b < 0) y = -y;
  return true;
}
int spf[MAXN];
map<int, int> m1;
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < MAXN; i++) {
    spf[i] = i;
  }
  for (int i = 4; i < MAXN; i += 2) spf[i] = 2;
  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < MAXN; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}
bool prime[MAXN];
void SieveOfEratosthenes(long long n = MAXN - 1) {
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
struct num {
  int val, index;
};
bool compare(num n1, num n2) { return (n1.val > n2.val); }
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, flag = 0, i, j;
    cin >> n;
    long long A[n];
    for (i = 0; i < n; ++i) cin >> A[i];
    sort(A, A + n);
    long long x = A[0] * A[n - 1];
    for (i = 1, j = n - 2; j >= i; ++i, --j) {
      if (A[i] * A[j] != x) {
        flag = 1;
        break;
      }
    }
    set<long long> s;
    for (i = 2; i <= sqrt(x) && flag == 0; ++i) {
      if (x % i == 0) {
        s.emplace(i);
        s.emplace(x / i);
      }
    }
    if (flag == 0 && s.size() == n)
      cout << x << "\n";
    else
      cout << -1 << "\n";
  }
  return 0;
}
