#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%i", &t);
  while (t--) {
    int n;
    scanf("%i", &n);
    vector<int> arr(n);
    for (auto &x : arr) scanf("%i", &x);
    sort(arr.begin(), arr.end());
    long long num = (long long)arr[0] * arr[n - 1];
    vector<int> div;
    for (long long x = 2; x * x <= num; x++) {
      if (num % x == 0) {
        div.push_back(x);
        div.push_back(num / x);
      }
    }
    sort(div.begin(), div.end());
    div.erase(unique(div.begin(), div.end()), div.end());
    if (div == arr)
      printf("%lli\n", num);
    else
      printf("-1\n");
  }
}
