#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int a[N];
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    long long x = (long long)a[1] * a[n];
    int ok = 1;
    for (int i = 1; i <= n; i++)
      if (x % (long long)a[i]) ok = 0;
    if (!ok) {
      printf("-1\n");
      continue;
    }
    int cnt = 0;
    for (long long i = 2; i <= sqrt(x); i++) {
      if (x % i == 0) {
        cnt++;
        if (x / i != i) cnt++;
      }
    }
    if (cnt == n)
      cout << x << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
