#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<long long> v;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    sort(v.begin(), v.end());
    long long ans = v[0] * v[v.size() - 1];
    int sum = 0, flag = 1;
    for (long long i = 2; i * i <= ans; i++) {
      if (ans % i == 0) {
        if (find(v.begin(), v.end(), i) == v.end() ||
            find(v.begin(), v.end(), ans / i) == v.end()) {
          flag = 0;
          break;
        }
        sum += 2;
        if (i * i == ans) sum--;
      }
    }
    if (sum == n && flag == 1)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
