#include <bits/stdc++.h>
using namespace std;
long long t, n, a[1000], ans;
int cal(long long x) {
  int res = 0;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) res += 2;
    if (i * i == x) res--;
  }
  return res;
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    ans = a[1] * a[n];
    if (cal(ans) != n)
      ans = -1;
    else
      for (int i = 1; i <= n; i++) {
        if (ans % a[i]) {
          ans = -1;
          break;
        }
      }
    cout << ans << endl;
  }
  return 0;
}
