#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
long long countDivisors(long long n) {
  long long cnt = 0;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt = cnt + 2;
    }
  }
  return cnt;
}
int main() {
  long long t;
  cin >> t;
  while (t-- > 0) {
    long long n, i, j;
    cin >> n;
    long long a[n];
    if (n == 1) {
      cin >> a[0];
      long long p = countDivisors(a[0] * a[0]);
      if (p != 1)
        cout << "-1" << endl;
      else
        cout << a[0] * a[0] << endl;
    } else {
      for (i = 0; i < n; i++) {
        cin >> a[i];
      }
      sort(a, a + n);
      long long p = a[0] * a[n - 1];
      for (i = 0; i < ((n / 2) + (n % 2)); i++) {
        if (p != a[i] * a[n - i - 1]) {
          break;
        }
      }
      if (i == ((n / 2) + (n % 2))) {
        long long p = countDivisors(a[0] * a[n - 1]);
        if (p == n) {
          cout << a[0] * a[n - 1] << endl;
        } else {
          cout << "-1" << endl;
        }
      } else
        cout << "-1" << endl;
    }
  }
}
