#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    long long int x = a[0] * a[n - 1];
    vector<int> b;
    for (long long int i = 2; i * i <= x; i++) {
      if (x % i == 0) {
        b.push_back(i);
        if (i != x / i) b.push_back(x / i);
      }
    }
    sort(b.begin(), b.end());
    if (n != b.size()) {
      cout << -1 << endl;
      continue;
    }
    int flag = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << x << endl;
    } else
      cout << -1 << endl;
  }
}
