#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long INFF = 1e18;
const long long MAXN = 510;
const long long MOD = 1e9 + 7;
bool ada[1000010];
long long tab[310];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    memset(ada, 0, sizeof(ada));
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> tab[i];
      ada[tab[i]] = 1;
    }
    sort(tab + 1, tab + n + 1);
    long long now = tab[1] * tab[n];
    long long l = 1;
    long long r = n;
    bool yes = 1;
    while (l <= r) {
      long long tmp = tab[l] * tab[r];
      if (tmp != now) {
        yes = 0;
        break;
      }
      ++l;
      --r;
    }
    if (!yes)
      cout << -1 << endl;
    else {
      for (long long i = 2; i * i <= now; i++)
        if (now % i == 0) {
          if (!ada[i]) {
            yes = 0;
            break;
          }
          if (!ada[now / i]) {
            yes = 0;
            break;
          }
        }
      if (!yes)
        cout << -1 << endl;
      else
        cout << now << endl;
    }
  }
}
