#include <bits/stdc++.h>
using namespace std;
long long int T, n;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> T;
  while (T--) {
    cin >> n;
    set<long long int> chk_div;
    vector<long long int> g;
    for (long long int i = 0, u; i < n; i++) cin >> u, g.push_back(u);
    sort(g.begin(), g.end());
    long long int p = (g[0] * g[n - 1]);
    for (long long int i = 2; i * i <= p; i++)
      if (!(p % i)) chk_div.insert(i), chk_div.insert(p / i);
    set<long long int> div(g.begin(), g.end());
    (chk_div == div) ? (cout << p << '\n') : (cout << "-1\n");
  }
  return 0;
}
