#include <bits/stdc++.h>
using namespace std;
int t, n;
int d[305];
int vis[1000005];
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(vis, 0, sizeof(vis));
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &d[i]);
      vis[d[i]] = 1;
    }
    sort(d, d + n);
    long long ans = 1ll * d[0] * d[n - 1];
    int flag = 1;
    for (int i = 1; i <= n / 2; i++) {
      if (ans != (1ll * d[i] * d[n - i - 1])) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      for (long long i = 2; i * i <= ans; i++) {
        if (ans % i == 0) {
          if (vis[i] == 0) {
            flag = 0;
            break;
          }
        }
      }
    }
    if (flag)
      printf("%lld\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
