#include <bits/stdc++.h>
using namespace std;
bool contradiction_check(unsigned long long int x,
                         vector<unsigned long long int>& vec) {
  set<unsigned long long int> s;
  unsigned long long int k, m, v = 0;
  set<unsigned long long int>::iterator st;
  s.clear();
  for (unsigned long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      s.insert(i);
      s.insert(x / i);
    }
  }
  k = vec.size();
  m = s.size();
  if (k != m)
    return true;
  else {
    for (st = s.begin(); st != s.end(); st++) {
      if (*st != vec[v] || x % vec[v] != 0) {
        return true;
      }
      v++;
    }
  }
  return false;
}
bool primality_check(unsigned long long int in) {
  if (in == 2)
    return false;
  else if (in > 2 && in % 2 == 0)
    return true;
  else {
    for (unsigned long long int i = 3; i * i <= in; i += 2)
      if (in % i == 0) return true;
  }
  return false;
}
int main() {
  unsigned long long int T, n, in, d, x;
  scanf("%llu", &T);
  vector<unsigned long long int> vec;
  vector<unsigned long long int>::iterator it;
  for (unsigned long long int i = 1; i <= T; i += 1) {
    scanf("%llu", &d);
    for (unsigned long long int j = 1; j <= d; j += 1) {
      scanf("%llu", &in);
      vec.push_back(in);
    }
    sort(vec.begin(), vec.end());
    if (d == 1) {
      bool y_n = primality_check(in);
      if (y_n == true)
        printf("-1\n");
      else
        printf("%llu\n", in * in);
    } else {
      unsigned long long int x = vec[0] * vec[d - 1];
      bool c_c = contradiction_check(x, vec);
      if (c_c == true)
        printf("-1\n");
      else {
        printf("%llu\n", x);
      }
    }
    vec.clear();
  }
  return 0;
}
