#include <bits/stdc++.h>
using namespace std;
int numOfDivisors(long long n) {
  int cnt = 0;
  long long sq = sqrt(n);
  for (int i = 2; i <= sq; ++i) {
    if (n % i == 0) cnt += 2;
  }
  if (sq * sq == n) --cnt;
  return cnt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; ++i) {
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    int i = 0, j = v.size() - 1;
    long long ans = v[i] * v[j];
    bool poss = 1;
    while (i <= j) {
      if (v[i++] * v[j--] != ans) {
        poss = 0;
        break;
      }
    }
    if (!poss)
      cout << -1 << '\n';
    else {
      if (v.size() == numOfDivisors(ans))
        cout << ans << '\n';
      else
        cout << -1 << '\n';
    }
  }
  return 0;
}
