#include <bits/stdc++.h>
using namespace std;
int n, m, N, T;
int dx[5] = {-1, 1, 0, 0}, dy[5] = {0, 0, -1, 1}, dz[3] = {-1, 1};
int ddx[9] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[9] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main(void) {
  cin >> n;
  while (n--) {
    cin >> m;
    vector<long long> a(m);
    for (int i = 0; i < m; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long x = a[0] * a[m - 1];
    vector<long long> b;
    for (int j = 2; j * 1ll * j <= x; j++) {
      if (x % j == 0) {
        b.push_back(j);
        if (j != x / j) {
          b.push_back(x / j);
        }
      }
    }
    sort(b.begin(), b.end());
    if (a == b)
      cout << x << endl;
    else
      cout << -1 << endl;
  }
}
