#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    map<int, int> a;
    int n, q = 0;
    cin >> n;
    long long int div[n];
    for (int i = 0; i < n; i++) cin >> div[i], a[div[i]] = 1;
    sort(div, div + n);
    long long int f = div[n - 1] * div[0];
    for (int i = 2; i <= sqrt(f); i++) {
      if (f % i == 0) {
        if (a[f / i] != 1 or a[i] != 1) {
          cout << -1 << endl;
          q = 1;
          break;
        } else
          a[f / i] = 0, a[i] = 0;
      }
    }
    if (q == 0) {
      for (int i = 0; i < n; i++) {
        if (a[div[i]] == 1) {
          cout << -1 << endl;
          q = 1;
          break;
        }
      }
    }
    if (q == 0) cout << f << endl;
  }
}
