#include <bits/stdc++.h>
using namespace std;
int n;
long long a[305], Lcm;
long long sol(long long x) {
  long long cnt = 0;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      cnt += 2;
      if (i * i == x) cnt--;
    }
  }
  return cnt;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int ok = 1;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    sort(a, a + n);
    if (n == 1)
      Lcm = a[0] * a[0];
    else
      Lcm = a[0] * a[n - 1];
    for (int i = 1; i < (n + 1) / 2; i++) {
      if (a[i] * a[n - 1 - i] != Lcm) {
        ok = 0;
        break;
      }
    }
    if (ok && sol(Lcm) == n)
      printf("%lld\n", Lcm);
    else
      puts("-1");
  }
}
