#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int o = 1; o <= t; o++) {
    int n, a = 1;
    cin >> n;
    long long p = 1;
    long long arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);
    if (n % 2 == 0) {
      p = arr[0] * arr[n - 1];
      for (int i = 2, j = 0; i <= sqrt(p); i++) {
        if (p % i == 0) {
          if (arr[j] != i || arr[n - 1 - j] != p / i) {
            a = 0;
            break;
          }
          j++;
        }
      }
      if (a == 0)
        cout << "-1\n";
      else {
        for (int i = 1; i < n / 2; i++) {
          if (p != arr[i] * arr[n - 1 - i]) {
            a = 0;
            break;
          }
        }
        if (a == 0)
          cout << "-1\n";
        else
          cout << p << endl;
      }
    } else {
      p = arr[n / 2] * arr[n / 2];
      for (int i = 2, j = 0; i <= sqrt(p); i++) {
        if (p % i == 0) {
          if (arr[j] != i || arr[n - 1 - j] != p / i) {
            a = 0;
            break;
          }
          j++;
        }
      }
      if (a == 0)
        cout << "-1\n";
      else {
        for (int i = 0; i < n / 2; i++) {
          if (p != arr[i] * arr[n - 1 - i]) {
            a = 0;
            break;
          }
        }
        if (a == 0)
          cout << "-1\n";
        else
          cout << p << endl;
      }
    }
  }
  return 0;
}
