#include <bits/stdc++.h>
using namespace std;
int a[400];
int check(long long int val, int n) {
  long long int vl = sqrt(val);
  int ct = 0;
  for (int h = 1; h <= vl; h++) {
    if (h != vl && val % h == 0) {
      ct += 2;
    }
    if (h == vl && 1LL * vl * vl == val)
      ct++;
    else if (h == vl && val % vl == 0)
      ct += 2;
  }
  if (ct - 2 == n)
    return 1;
  else
    return 0;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int h = 0; h < n; h++) cin >> a[h];
    sort(a, a + n);
    long long int val, cal;
    int f = 1;
    if (n % 2 == 0) {
      val = 1LL * a[0] * a[n - 1];
      for (int h = 1; h < n / 2; h++) {
        cal = 1LL * a[h] * a[n - h - 1];
        if (cal != val) {
          f = 0;
          break;
        }
      }
    } else {
      val = 1LL * a[n / 2] * a[n / 2];
      for (int h = 0; h < n / 2; h++) {
        cal = 1LL * a[h] * a[n - h - 1];
        if (cal != val) {
          f = 0;
          break;
        }
      }
    }
    if (f == 0) {
      cout << -1 << endl;
    } else {
      if (check(val, n))
        cout << val << endl;
      else
        cout << -1 << endl;
    }
  }
}
