#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, a[300], b[300], k = 0;
  long long int x;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    for (int j = 0; j < n; j++) cin >> a[j];
    sort(a, a + n);
    x = a[0] * a[n - 1];
    for (int j = 2; j <= sqrt(x); j++) {
      if (k > n) break;
      if (x % j == 0)
        if (j == x / j) {
          b[k] = j;
          k++;
        } else {
          b[k] = j;
          b[k + 1] = x / j;
          k += 2;
        }
    }
    if (k != n)
      cout << -1 << endl;
    else {
      sort(b, b + k);
      int c;
      for (c = 0; c < n; c++)
        if (a[c] != b[c]) break;
      if (c == n)
        cout << x << endl;
      else
        cout << -1 << endl;
    }
    k = 0;
  }
}
