#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
vector<long long int> h(101, 0);
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> v1(n), v2;
    for (int i = 0; i < n; i++) {
      cin >> v1[i];
    }
    sort(v1.begin(), v1.end());
    long long int ans = v1[0] * v1[n - 1];
    for (int i = 2; i * 1ll * i <= ans; i++) {
      if (ans % i == 0) {
        v2.push_back(i);
        if (ans / i != i) v2.push_back(ans / i);
      }
    }
    sort(v2.begin(), v2.end());
    if (v1 == v2)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
