#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long num[304];
    for (int i = 0; i < n; i++) cin >> num[i];
    sort(num, num + n);
    long long res = -1;
    bool ok = true;
    for (int i = 0, j = n - 1; i <= j; i++, j--) {
      if (res == -1)
        res = num[i] * num[j];
      else {
        if (res != num[i] * num[j]) {
          ok = false;
          break;
        }
      }
    }
    int m = 0;
    for (long long x = 1; x * x <= res; x++) {
      if (res % x == 0) m += 2;
      if (x * x == res) m -= 1;
    }
    ok = ok && ((m - 2) == n);
    cout << (ok ? res : -1) << endl;
  }
  return 0;
}
