#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m, f, x, i, j, root, k, d[350];
    vector<int> v;
    cin >> n;
    for (i = 0; i < n; i++) cin >> d[i];
    sort(d, d + n);
    x = d[n - 1] * d[0];
    root = sqrt(x + 1);
    for (i = 2; i <= root; i++) {
      if (x % i == 0) {
        v.push_back(i);
        m = x / i;
        if (m != i) v.push_back(m);
      }
    }
    sort(v.begin(), v.end());
    if (v.size() == n) {
      f = 0;
      for (i = 0; i < n && i < v.size(); i++) {
        if (d[i] != v[i]) {
          f = 1;
          break;
        }
      }
      if (f == 0)
        cout << x << endl;
      else
        cout << "-1" << endl;
    } else
      cout << "-1" << endl;
  }
  return 0;
}
