#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, q, ar[100010], ar2[100010], i, j, cnt, store, l, r, s, m, p, c;
  cin >> t;
  while (t--) {
    cin >> q;
    for (i = 0; i < q; i++) {
      cin >> ar[i];
    }
    sort(ar, ar + q);
    l = (ar[0]) * (ar[q - 1]);
    m = sqrt(l);
    j = 0;
    c = 0;
    for (i = 2; i <= m; i++) {
      if (l % i == 0) {
        if (l / i == i) {
          ar2[j++] = i;
        } else {
          ar2[j++] = i;
          ar2[j++] = l / i;
        }
        c = 1;
      }
    }
    sort(ar2, ar2 + j);
    cnt = 0;
    for (j = 0; j < q; j++) {
      if ((ar[j] != ar2[j])) {
        cnt = 1;
        break;
      }
    }
    if (cnt == 0)
      cout << l << endl;
    else
      cout << "-1" << endl;
  }
}
