#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int main() {
  int T;
  while (scanf("%d", &T) != EOF) {
    while (T--) {
      vector<long long> a, b;
      int n;
      scanf("%d", &n);
      for (int i = 0; i < n; i++) {
        long long c;
        scanf("%I64d", &c);
        a.push_back(c);
      }
      sort(a.begin(), a.end());
      long long ans = a[0] * a[n - 1];
      for (long long i = 2; i * i <= ans; i++) {
        if (ans % i == 0) {
          b.push_back(i);
          if (i != ans / i) b.push_back(ans / i);
        }
      }
      sort(b.begin(), b.end());
      if (a == b)
        printf("%I64d\n", ans);
      else
        printf("-1\n");
    }
  }
  return 0;
}
