#include <bits/stdc++.h>
template <typename T>
inline void read(T& x) {
  T res = 0, flag = 1;
  char ch;
  ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    res = res * 10 + ch - 48;
    ch = getchar();
  }
  x = res * flag;
}
const int N = 300 + 2;
int t, n, x;
std::vector<long long> d, c;
int main() {
  read(t);
  while (t--) {
    read(n);
    d.clear();
    c.clear();
    for (int i = 0; i < n; ++i) read(x), d.push_back(x);
    std::sort(d.begin(), d.end());
    long long x = d[0] * d[n - 1], s = sqrt(x);
    for (long long i = 2; i <= s; ++i) {
      if (!(x % i)) c.push_back(i), c.push_back(x / i);
      if (i * i == x) c.pop_back();
    }
    if (c.size() != n) {
      puts("-1");
      continue;
    }
    std::sort(c.begin(), c.end());
    printf("%lld\n", (d == c) ? x : -1);
  }
}
