    #include<bits/stdc++.h>
    // #include<ext/pb_ds/assoc_container.hpp>
    // #include<ext/pb_ds/tree_policy.hpp>
using namespace std;
        // using namespace __gnu_pbds;

typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii>vpii;
typedef std::vector<lli> vll;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vbb;
typedef map<lli,lli>mll;
typedef set<lli> sll;
typedef multiset<lli> msll;
const lli MOD=1e9 +7;
const lli INF=3e18;

    #define forr(i,p,n) for(i=p; i<n; i++)
    #define forn(i,p,n) for(i=p; i<=n; i++)
    #define forl(i,n,p) for(i=n; i>=p; i--)
    #define be(a) a.begin(),a.end()
    #define mp make_pair
    #define eb emplace_back
    #define pb push_back
    #define F first
    #define S second
    #define all(a)     (a).begin(),(a).end()
    #define PI 3.14159265358979323846
    #define lb lower_bound
    #define ub upper_bound
    #define endl "\n"
    #define bpcl(x) __builtin_popcountll(x)
    #define deb(vari) cerr<<#vari<<" = "<<vari<<endl;
                // #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
lli power(lli base, lli exp) {lli res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
lli bitc(lli n,lli x){return ((n>>x)&1);}
lli __gcd(lli a,lli b){return b==0?a:__gcd(b,a%b);}
lli fsub(lli a,lli b,lli p=MOD){return ((a%p)-(b%p)+p)%p;}
lli fmult(lli a,lli b, lli p=MOD) {return ((((a%p)*(b%p))%p)+p)%p;}
lli fadd(lli a, lli b, lli p=MOD) {return ((a%p + b%p)%p+p)%p;}
                                        // lli add(lli a,lli b,lli p=MOD){//if(a+b>=p){//return (a+b)-p;//  }//return a+b;// }
lli fpow(lli n, lli k, lli p = MOD) {lli r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
lli inv(lli a, lli p = MOD) {return fpow(a, p - 2, p);}
lli fdiv(lli a,lli b,lli p=MOD){lli yinv=inv(b);lli ans=(a*yinv)%p;return ((ans)%p+p)%p;}
lli ceil(lli a,lli b){return ceil((ld)a/b);}

    template<typename T>istream &operator>>(istream &in, vector<T> &a) {for (auto &item : a) {in >> item;}return in;}template<typename T,typename U>ostream &operator<<(ostream &out, pair<T,U> &a) {cout<<a.F<<" "<<a.S;return out;}
    template<typename T,typename U>
istream &operator>>(istream &out, pair<T,U> &a) {cin>>a.F>>a.S;return out;}
    template<typename T,typename U>
ostream &operator<<(ostream &out, map<T,U> &a) {for (auto &item : a) {out << item << endl;}return out;}
    template<typename T>
ostream &operator<<(ostream &out, vector<T> &a) {for (auto &item : a) {out << item << " ";}return out;}
    template<typename T>
ostream &operator<<(ostream &out, vector<vector<T>> &a) {for (auto &item : a) {out << item << "\n";}return out;}
    template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
	static_assert(D >= 1, "Vector dimension must be greater than zero!");
                          template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
    template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, T val = T()) : vector<T>(n, val) {
	}
};
/*
Vec<5, int> dp;
dp.assign(n1, {n2, n3, n4, n5, default_value});
*/

                    // Vec<2,lli>mat(n,n,1);
    #define print(a) for(auto p:a) cout<<p<<endl; cout<<endl;
    #define read(a) for(auto &p:a)cin>>p>>endl;
std::vector<bool> is_prime;
std::vector<lli> primes;
void sieve(lli n){is_prime.resize(n+2,true);primes.clear();lli p;for(p=2;p*p<=n;p++){if(is_prime[p]){lli i;for(i=p*p;i<=n;i+=p){is_prime[i]=false;}}}is_prime[0]=is_prime[1]=false;lli i;for(i=2;i<=n;i++){if(is_prime[i]){primes.eb(i);}}}
mll prime_factors(lli n){  mll s;lli i;lli tc=0;while(n%2==0){tc++;n/=2;}if(tc>0){s[2]=tc;}for(i=3;i<=sqrt(n);i+=2){tc=0;while(n%i==0){tc++;n/=i;}if(tc>0){s[i]=tc;}}if(n>2){s[n]+=1;}return s;}
std::vector<lli> fact_vec;
void fact_fun(lli n){fact_vec.resize(n+10);lli i;fact_vec[0]=1;for(i=1;i<=n+2;i++){fact_vec[i]=(fact_vec[i-1]*i)%MOD;}}
vll p2;
void power_2(lli n,lli m=MOD){ lli i;p2.eb(1);forr(i,0,n){p2.eb(fmult(p2.back(),2));}}
lli ncr(lli n,lli r){if(r>n)return 0;return fdiv(fact_vec[n],fmult(fact_vec[r],fact_vec[n-r]));}
vll spf;void sieve2(lli MAXN) { MAXN+=10;spf.resize(MAXN,0);spf[1] = 1; for (lli i=2; i<MAXN; i++) spf[i] = i;     for (lli i=4; i<MAXN; i+=2) spf[i] = 2; for (lli i=3; i*i<MAXN; i++) {         if (spf[i] == i) { for (lli j=i*i; j<MAXN; j+=i) {if (spf[j]==j) spf[j] = i; }} } }
const int mi[4]={-1, 0, 1, 0}, mj[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
mll getFactorization(lli x)
{
	mll ret;
	while (x != 1){
        // ret.eb(spf[x]);
		ret[spf[x]]++;
		x = x / spf[x];
	} return ret;
}

// class Sol{
// public:
//     Sol(){
//         lli  i,j;
//     }
// };

int main(){

	lli i,j;
            #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt",  "w", stdout);
            #endif

	ios::sync_with_stdio(false);
	cin.tie(0);

	lli ti;

	ti=1;
        // cin>>ti;
	while(ti--){
		lli n,k;
		cin>>n>>k;
		vll a(n),b(n);
		cin>>a>>b;
		ld x=INF;
		forr(i,0,n){
			x=min(x,(ld)b[i]/a[i]);
		}
		x=min(x,(ld)k);
		cout<<fixed<<setprecision(5);
		ld ans=0;
		for(auto p:a){
			ans+= (ld)p*x;
		}
		ans=min(ans,(ld)k);
		cout<<fixed<<setprecision(5);
		cout<<ans<<endl;
		return 0;
	}

}


    #include<bits/stdc++.h>
    // #include<ext/pb_ds/assoc_container.hpp>
    // #include<ext/pb_ds/tree_policy.hpp>
using namespace std;
        // using namespace __gnu_pbds;

typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii>vpii;
typedef std::vector<lli> vll;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vbb;
typedef map<lli,lli>mll;
typedef set<lli> sll;
typedef multiset<lli> msll;
const lli MOD=1e9 +7;
const lli INF=3e18;

    #define forr(i,p,n) for(i=p; i<n; i++)
    #define forn(i,p,n) for(i=p; i<=n; i++)
    #define forl(i,n,p) for(i=n; i>=p; i--)
    #define be(a) a.begin(),a.end()
    #define mp make_pair
    #define eb emplace_back
    #define pb push_back
    #define F first
    #define S second
    #define all(a)     (a).begin(),(a).end()
    #define PI 3.14159265358979323846
    #define lb lower_bound
    #define ub upper_bound
    #define endl "\n"
    #define bpcl(x) __builtin_popcountll(x)
    #define deb(vari) cerr<<#vari<<" = "<<vari<<endl;
                // #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
lli power(lli base, lli exp) {lli res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
lli bitc(lli n,lli x){return ((n>>x)&1);}
lli __gcd(lli a,lli b){return b==0?a:__gcd(b,a%b);}
lli fsub(lli a,lli b,lli p=MOD){return ((a%p)-(b%p)+p)%p;}
lli fmult(lli a,lli b, lli p=MOD) {return ((((a%p)*(b%p))%p)+p)%p;}
lli fadd(lli a, lli b, lli p=MOD) {return ((a%p + b%p)%p+p)%p;}
                                        // lli add(lli a,lli b,lli p=MOD){//if(a+b>=p){//return (a+b)-p;//  }//return a+b;// }
lli fpow(lli n, lli k, lli p = MOD) {lli r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
lli inv(lli a, lli p = MOD) {return fpow(a, p - 2, p);}
lli fdiv(lli a,lli b,lli p=MOD){lli yinv=inv(b);lli ans=(a*yinv)%p;return ((ans)%p+p)%p;}
lli ceil(lli a,lli b){return ceil((ld)a/b);}

    template<typename T>istream &operator>>(istream &in, vector<T> &a) {for (auto &item : a) {in >> item;}return in;}template<typename T,typename U>ostream &operator<<(ostream &out, pair<T,U> &a) {cout<<a.F<<" "<<a.S;return out;}
    template<typename T,typename U>
istream &operator>>(istream &out, pair<T,U> &a) {cin>>a.F>>a.S;return out;}
    template<typename T,typename U>
ostream &operator<<(ostream &out, map<T,U> &a) {for (auto &item : a) {out << item << endl;}return out;}
    template<typename T>
ostream &operator<<(ostream &out, vector<T> &a) {for (auto &item : a) {out << item << " ";}return out;}
    template<typename T>
ostream &operator<<(ostream &out, vector<vector<T>> &a) {for (auto &item : a) {out << item << "\n";}return out;}
    template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
	static_assert(D >= 1, "Vector dimension must be greater than zero!");
                          template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
    template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, T val = T()) : vector<T>(n, val) {
	}
};
/*
Vec<5, int> dp;
dp.assign(n1, {n2, n3, n4, n5, default_value});
*/

                    // Vec<2,lli>mat(n,n,1);
    #define print(a) for(auto p:a) cout<<p<<endl; cout<<endl;
    #define read(a) for(auto &p:a)cin>>p>>endl;
std::vector<bool> is_prime;
std::vector<lli> primes;
void sieve(lli n){is_prime.resize(n+2,true);primes.clear();lli p;for(p=2;p*p<=n;p++){if(is_prime[p]){lli i;for(i=p*p;i<=n;i+=p){is_prime[i]=false;}}}is_prime[0]=is_prime[1]=false;lli i;for(i=2;i<=n;i++){if(is_prime[i]){primes.eb(i);}}}
mll prime_factors(lli n){  mll s;lli i;lli tc=0;while(n%2==0){tc++;n/=2;}if(tc>0){s[2]=tc;}for(i=3;i<=sqrt(n);i+=2){tc=0;while(n%i==0){tc++;n/=i;}if(tc>0){s[i]=tc;}}if(n>2){s[n]+=1;}return s;}
std::vector<lli> fact_vec;
void fact_fun(lli n){fact_vec.resize(n+10);lli i;fact_vec[0]=1;for(i=1;i<=n+2;i++){fact_vec[i]=(fact_vec[i-1]*i)%MOD;}}
vll p2;
void power_2(lli n,lli m=MOD){ lli i;p2.eb(1);forr(i,0,n){p2.eb(fmult(p2.back(),2));}}
lli ncr(lli n,lli r){if(r>n)return 0;return fdiv(fact_vec[n],fmult(fact_vec[r],fact_vec[n-r]));}
vll spf;void sieve2(lli MAXN) { MAXN+=10;spf.resize(MAXN,0);spf[1] = 1; for (lli i=2; i<MAXN; i++) spf[i] = i;     for (lli i=4; i<MAXN; i+=2) spf[i] = 2; for (lli i=3; i*i<MAXN; i++) {         if (spf[i] == i) { for (lli j=i*i; j<MAXN; j+=i) {if (spf[j]==j) spf[j] = i; }} } }
const int mi[4]={-1, 0, 1, 0}, mj[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
mll getFactorization(lli x)
{
	mll ret;
	while (x != 1){
        // ret.eb(spf[x]);
		ret[spf[x]]++;
		x = x / spf[x];
	} return ret;
}

// class Sol{
// public:
//     Sol(){
//         lli  i,j;
//     }
// };

int main(){

	lli i,j;
            #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt",  "w", stdout);
            #endif

	ios::sync_with_stdio(false);
	cin.tie(0);

	lli ti;

	ti=1;
        // cin>>ti;
	while(ti--){
		lli n,k;
		cin>>n>>k;
		vll a(n),b(n);
		cin>>a>>b;
		lli x=*min_element(all(b));
		lli sum=accumulate(all(a),0ll);
		if(sum*x<=k){
			cout<<sum*x<<endl;
		}else{
			cout<<k<<endl;
		}
		return 0;
	}

}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int t, n, a[305];
long long maxn;
bool judge(int l, int r, long long num) {
	for(int i = l + 1; i < r; ++i) {
		if(num % i == 0) return false;
	}
	return true;
}

int main() {
	cin >> t;
	a[0] = 1;
	while(t--) {
		bool pd = 1;
		cin >> n;
		for(int i = 1; i <= n; ++i) {
			cin >> a[i];
		}
		sort(a, a + n + 1);
		long long t1 = a[1];
		long long t2 = a[n];
		maxn = t1 * t2;
		if(judge(1, a[1], maxn) == 0) {
			pd = 0;
		}
		for(int i = 1, j = n; i <= j;) {
			if(j - i == 1 && !judge(a[i], a[j], maxn)) {
				pd = 0;
				break;
			}
			if(i > 1 && !judge(a[i - 1], a[i], maxn)) {
				pd = 0;
				break;
			}
			if(maxn / a[i] == a[j] && maxn % a[i] == 0) {
				i++;
				j--;
			}
			else {
				pd = 0;
				break;
			}
		}
		pd ? cout << maxn << endl : cout << -1 << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int t, n, a[305];
int gcd(int x, int y) {
	if(y == 0) return x;
	else return gcd(y, x % y);
}

int main() {
	cin >> t;
	while(t--) {
		cin >> n;
		for(int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		sort(a, a + n);
		int maxn = a[n - 1];
		for(int i = 0; i < n; ++i) {
			if(maxn % a[i] != 0) {
				maxn = a[i] * maxn / gcd(a[i], maxn);
			}
		}
		if(maxn == a[n - 1]) maxn *= 2;
		cout << maxn << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int t, n, a[305];
bool judge(int l, int r, int num) {
	for(int i = l + 1; i < r; ++i) {
		if(num % i == 0) return false;
	}
	return true;
}

int main() {
	cin >> t;
	while(t--) {
		bool pd = 1;
		cin >> n;
		a[0] = 1;
		for(int i = 1; i <= n; ++i) {
			cin >> a[i];
		}
		sort(a, a + n + 1);
		int maxn = a[1] * a[n];

		for(int i = 2, j = n - 1; i <= j;) {
			if(maxn / a[i] == a[j]) {
				i++;
				j--;
			}
			else {
				pd = 0;
				break;
			}
			if(j - i == 1 && !judge(a[i], a[j], maxn)) {
				pd = 0;
				break;
			}
		}
		pd ? cout << maxn << endl : cout << -1 << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int t, n, a[305];
long long maxn;
bool judge(int l, int r, long long num) {
	for(int i = l + 1; i < r; ++i) {
		if(num % i == 0) return false;
	}
	return true;
}
bool judge1(int r, long long maxn) {
	for(int i = 2; i < r; ++i) {
		if(maxn % i == 0) return false;
	}
	return true;
}

int main() {
	cin >> t;
	while(t--) {
		bool pd = 1;
		cin >> n;
		a[0] = 1;
		for(int i = 1; i <= n; ++i) {
			cin >> a[i];
		}
		sort(a, a + n + 1);
		long long t1 = a[1];
		long long t2 = a[n];
		maxn = t1 * t2;
		if(judge1(a[1], maxn) == 0) {
			pd = 0;
		}
		for(int i = 2, j = n - 1; i <= j;) {
			if(maxn / a[i] == a[j]) {
				i++;
				j--;
			}
			else {
				pd = 0;
				break;
			}
			if(j - i == 1 && !judge(a[i], a[j], maxn)) {
				pd = 0;
				break;
			}
		}
		pd ? cout << maxn << endl : cout << -1 << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

int t, n, a[305];
long long maxn;
bool judge(int l, int r, long long num) {
	for(int i = l + 1; i < r; ++i) {
		if(num % i == 0) return false;
	}
	return true;
}

int main() {
	cin >> t;
	while(t--) {
		bool pd = 1;
		cin >> n;
		a[0] = 1;
		for(int i = 1; i <= n; ++i) {
			cin >> a[i];
		}
		sort(a, a + n + 1);
		long long t1 = a[1];
		long long t2 = a[n];
		maxn = t1 * t2;
		for(int i = 2, j = n - 1; i <= j;) {
			if(maxn / a[i] == a[j]) {
				i++;
				j--;
			}
			else {
				pd = 0;
				break;
			}
			if(j - i == 1 && !judge(a[i], a[j], maxn)) {
				pd = 0;
				break;
			}
		}
		pd ? cout << maxn << endl : cout << -1 << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(int *p,int n)
{
	for(int i=0;i<n;i++)
	{
		int m=p[i],j;
		for(j=2;j<sqrt(m);j++)
		{
			if(m%j==0)
			{
				int r=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j||p[k]==m/j)
					r++;
				}
				if(r!=2)
				return 0;
			}
		}
		if(j*j==n)
		{
			int r=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					r++;
				}
				if(r==0)
				return 0;
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;

		int *p=new int[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		sort(p,p+n);
		if(!check(p,n))
		cout<<"-1\n";
		else
		{
			if(n==1)
			{
				long long m=(long long)p[0]*(long long)p[0];
				cout<<m<<endl;
			}
			else
			{
				int r=0;
				long long m=(long long)p[0]*(long long)p[n-1];
				int x=1,y=n-2;
				while(x<=n/2)
				{

				if((long long)p[x]*(long long)p[y]!=m)
				{
				cout<<"-1\n";
				r=1;
				break;}
				x++;
				y--;
			}
			if(r==0)
			cout<<m<<endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long *p,int n)
{
	for(int i=0;i<n;i++)
	{
		long long t=p[i];
		for(long long j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		if(n==1)
		cout<<p[0]*p[0]<<endl;
		else
		{
			sort(p,p+n);
			if(!check(p,n))
			{
			cout<<"-1\n";}
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					break;
				}
				x++;
				y--;
			}
			if(x==n/2+1)
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(int *p,int n)
{
	for(int i=0;i<n;i++)
	{
		int m=p[i],j;
		for(j=2;j<sqrt(m);j++)
		{
			if(m%j==0)
			{
				int r=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j||p[k]==m/j)
					r++;
				}
				if(r!=2)
				return 0;
			}
		}
		if(j*j==m)
		{
			int r=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					r++;
				}
				if(r==0)
				return 0;
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;

		int *p=new int[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		sort(p,p+n);
		if(!check(p,n))
		cout<<"-1\n";
		else
		{
			if(n==1)
			{
				long long m=(long long)p[0]*(long long)p[0];
				cout<<m<<endl;
			}
			else
			{
				int r=0;
				long long m=(long long)p[0]*(long long)p[n-1];
				int x=1,y=n-2;
				while(x<=n/2)
				{

				if((long long)p[x]*(long long)p[y]!=m)
				{
				cout<<"-1\n";
				r=1;
				break;}
				x++;
				y--;
			}
			if(r==0)
			cout<<m<<endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(int *p,int n)
{
	for(int i=0;i<n;i++)
	{
		int t=p[i];
		for(int j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int *p=new int[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		if(n==1)
		cout<<p[0]*p[0]<<endl;
		else
		{
			sort(p,p+n);
			if(!check(p,n))
			cout<<"-1\n";
			else
			{

			int m=p[0]*p[n-1];
			int x=1,y=n-2;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					return 0;
				}
				x++;
				y--;
			}
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long* *p,int n)
{
	for(int i=0;i<n;i++)
	{
		int t=p[i];
		for(int j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		if(n==1)
		cout<<p[0]*p[0]<<endl;
		else
		{
			sort(p,p+n);
			if(!check(p,n))
			cout<<"-1\n";
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					return 0;
				}
				x++;
				y--;
			}
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long *p,int n)
{
	for(int i=0;i<n;i++)
	{
		long long t=p[i];
		for(long long j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		if(n==1)
		cout<<p[0]*p[0]<<endl;
		else
		{
			sort(p,p+n);
			if(!check(p,n))
			cout<<"-1\n";
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					return 0;
				}
				x++;
				y--;
			}
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long *p,int n)
{
	for(int i=0;i<n;i++)
	{
		long long t=p[i];
		for(long long j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		sort(p,p+n);
		if(!check(p,n))
		{
			cout<<"-1\n";}
		else
		{
			if(n==1)
		cout<<p[0]*p[0]<<endl;
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2,l=0;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					l=1;
					break;
				}
				x++;
				y--;
			}
			if(l==0)
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long *p,int n)
{
	for(int i=0;i<n;i++)
	{
		long long t=p[i];
		for(long long j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		if(n==1)
		cout<<p[0]*p[0]<<endl;
		else
		{
			sort(p,p+n);
			if(!check(p,n))
			{
			cout<<"-1\n";return 0;}
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					return 0;
				}
				x++;
				y--;
			}
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long *p,int n)
{
	for(int i=0;i<n;i++)
	{
		long long t=p[i];
		for(long long j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					{
						m=1;
						break;
					}
				}
				if(m==0)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		if(!check(p,n))
		{
			cout<<"-1\n";}
		else
		{
			if(n==1)
		cout<<p[0]*p[0]<<endl;
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					break;
				}
				x++;
				y--;
			}
			if(x==n/2+1)
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(long long *p,int n)
{
	for(int i=0;i<n;i++)
	{
		long long t=p[i];
		for(long long j=2;j<=sqrt(t);j++)
		{
			if(t%j==0)
			{
				int m=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j||p[k]==t/j)
					{
						m++;
					}
				}
				if(m!=2)
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		long long *p=new long long[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		sort(p,p+n);
		if(!check(p,n))
		{
			cout<<"-1\n";}
		else
		{
			if(n==1)
		cout<<p[0]*p[0]<<endl;
			else
			{

			long long m=p[0]*p[n-1];
			int x=1,y=n-2,l=0;
			while(x<=n/2)
			{
				if(p[x]*p[y]!=m)
				{
					cout<<"-1\n";
					l=1;
					break;
				}
				x++;
				y--;
			}
			if(l==0)
			cout<<m<<endl;
		}

		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(int *p,int n)
{
	for(int i=0;i<n;i++)
	{
		int m=p[i],j;
		for(j=2;j<sqrt(n);j++)
		{
			if(m%j==0)
			{
				int r=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j||p[k]==m/j)
					r++;
				}
				if(r!=2)
				return 0;
			}
		}
		if(j*j==n)
		{
			int r=0;
				for(int k=0;k<i;k++)
				{
					if(p[k]==j)
					r++;
				}
				if(r==0)
				return 0;
		}
	}
	return 1;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;

		int *p=new int[n];
		for(int i=0;i<n;i++)
		cin>>p[i];

		sort(p,p+n);
		if(!check(p,n))
		cout<<"-1\n";
		else
		{
			if(n==1)
			{
				long long m=(long long)p[0]*(long long)p[0];
				cout<<m<<endl;
			}
			else
			{
				int r=0;
				long long m=(long long)p[0]*(long long)p[n-1];
				int x=1,y=n-2;
				while(x<=n/2)
				{

				if((long long)p[x]*(long long)p[y]!=m)
				{
				cout<<"-1\n";
				r=1;
				break;}
				x++;
				y--;
			}
			if(r==0)
			cout<<m<<endl;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=v[1]*v[n], y=0, l=2, r=n-1, z=0;
		while(r>=l){
			if(v[l]*v[r]!=x){
				y=1;
				break;
			}
			l++, r--;
		}
		for(int i=2; i<sqrt(x); i++)
			if(x%i==0)
				z+=2;
		if(y==0 and y==n)
			cout<<x<<endl;
		else
			puts("-1");
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

int t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		int x=1;
		for(int i=1; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i]*2)/(__gcd(x, v[i]*2));
		}
		cout<<x<<endl;;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		if(n==1){
			cout<<v[1]*v[1]<<endl;
			continue;
		}
		sort(v+1, v+1+n);
		ll x=v[1];
		for(int i=2; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i])/(__gcd(x, v[i]));
		}
		if(x>1e15 or x<0)
			cout<<-1<<endl;
		else if(x!=v[n])
			cout<<x<<endl;
		else
			cout<<x*2<<endl;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=1;
		for(int i=1; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i]*2)/(__gcd(x, v[i]*2));
		}
		cout<<x<<endl;;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=v[1]*v[n], y=0, l=2, r=n-1, z=0;
		while(r>=l){
			if(v[l]*v[r]!=x){
				y=1;
				break;
			}
			l++, r--;
		}
		for(int i=2; i<=sqrt(x); i++)
		{
			if(x%i==0)
			{
				if(x/i!=i)
					z+=2;
				else
					z++;
			}
		}
		if(y==0 and z==n)
			cout<<x<<endl;
		else
			puts("-1");
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		if(n==1){
			cout<<v[1]*v[1]<<endl;
			continue;
		}
		sort(v+1, v+1+n);
		ll x=v[1];
		for(int i=2; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i])/(__gcd(x, v[i]));
		}
		if(x!=v[n])
			cout<<x<<endl;
		else
			cout<<x*2<<endl;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=v[1]*v[n], y=0, l=2, r=n-1, z=0;
		while(r>=l){
			if(v[l]*v[r]!=x){
				y=1;
				break;
			}
			l++, r--;
		}
		for(int i=2; i<x; i++)
			if(x%i==0)
				z++;
		if(y==0 and z==n)
			cout<<x<<endl;
		else
			puts("-1");
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		if(n==1){
			cout<<v[1]*v[1]<<endl;
			continue;
		}
		sort(v+1, v+1+n);
		ll x=v[1];
		for(int i=2; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i])/(__gcd(x, v[i]));
		}
		if(x>1e18 or x<0)
			cout<<-1<<endl;
		else if(x!=v[n])
			cout<<x<<endl;
		else
			cout<<x*2<<endl;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=v[1];
		for(int i=2; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i])/(__gcd(x, v[i]));
		}
		if(x!=v[n])
			cout<<x<<endl;
		else
			cout<<x*2<<endl;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=v[1];
		for(int i=2; i<=n; i++)
		{
			if(x%v[i]!=0)
				x=(x*v[i]*2)/(__gcd(x, v[i]*2));
		}
		cout<<x<<endl;;
	}

}


#include <bits/stdc++.h>
#define N 100009
#define pii pair <int, int>
#define ff first
#define ss second
#define pb push_back
#define ll long long

using namespace std;

ll t, n, m, v[N];

int main(){
	cin>>t;
	for(int j=1; j<=t; j++){
		cin>>n;
		for(int i=1; i<=n; i++)
			cin>>v[i];
		sort(v+1, v+1+n);
		ll x=v[1]*v[n], y=0, l=2, r=n-1;
		while(r>=l){
			if(v[l]*v[r]!=x){
				y=1;
				break;
			}
			l++, r--;
		}
		if(y==1)
			puts("-1");
		else
			cout<<x<<endl;
	}

}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll geshu(ll a)
{
	int sum=0;
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		ll a[500];
		scanf("%d",&n);
		ll ans=1;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
			if(ans%a[i]==0)continue;
			ans=ans*a[i]/gcd(a[i],ans);
		}
		for(int i=1;i<=n;i++)
		{
			if(ans==a[i])
			{
				ans=ans*ans;
				continue;
			}
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				break;
			}
		}
		if(geshu(ans)==n)printf("%lld\n",ans);
		else printf("-1\n");
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				flag=0;
				break;
			}
		}
		if(geshu(ans)!=n)
		{
			printf("-1\n");
			continue;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int geshu(int a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		scanf("%d",&n);
		int ans=1;
		int maxed=-5;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&b);
			if(b>maxed)maxed=b;
			ans=ans*b/gcd(b,ans);
		}
		if(maxed==ans)
		{
			if(ans>2)
			{
				printf("-1\n");
				return 0;
			}
			else ans*=2;
		}
		if(geshu(ans)!=n)
		printf("-1\n");
		else
		printf("%d\n",ans);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll geshu(ll a)
{
	int sum=0;
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		ll a[500];
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				flag=0;
				break;
			}
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=2;i<=n-1;i++)
		{
			if(ans%a[i]!=0)
			{
				//printf("%lld\n",ans%a[i]);
				flag=0;
				return 0;
			}
		}
		if(geshu(ans)!=n)
		{
			flag=0;
			printf("-1\n");
			return 0;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll geshu(ll a)
{
	int sum=0;
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		ll a[500];
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		for(int i=1;i<=n;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				return 0;
			}
		}
		if(geshu(ans)==n)printf("%lld\n",ans);
		else printf("-1\n");
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int geshu(int a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		scanf("%d",&n);
		int ans=1;
		int maxed=-5;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&b);
			if(b>maxed)maxed=b;
			ans=ans*b/gcd(b,ans);
		}
		if(maxed==ans)ans*=ans;
		if(geshu(ans)!=n)
		printf("-1\n");
		else
		printf("%d\n",ans);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=2;i<=n-1;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("%lld\n",ans%a[i]);
				flag=0;
				break;
			}
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
int geshu(int a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=2;i<=n-1;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("%lld\n",ans%a[i]);
				flag=0;
				return 0;
			}
		}
		if(geshu(ans)!=n)
		{
			flag=0;
			printf("-1\n");
			return 0;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				break;
				return 0;
			}
		}
		if(geshu(ans)!=n)
		{
			printf("-1\n");
			return 0;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if(ans%a[i]!=0)
			{

				flag=0;
				break;
			}
		}
		if(geshu(ans)!=n)
		{
			printf("-1\n");

		}
		else if(flag)printf("%lld\n",ans);
		else printf("-1\n");

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=2;i<=n-1;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				flag=0;
				return 0;
			}
		}
		if(geshu(ans)!=n)
		{
			flag=0;
			printf("-1\n");
			return 0;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int geshu(int a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		scanf("%d",&n);
		int ans=1;
		int maxed=-5;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&b);
			if(b>maxed)maxed=b;
			ans=ans*b/gcd(b,ans);
		}
		if(maxed==ans)
		{
			ans*=ans;
		}
		if(geshu(ans)!=n)
		printf("-1\n");
		else
		printf("%d\n",ans);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll geshu(ll a)
{
	int sum=0;
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,b;
		ll a[500];
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		if(geshu(ans)==n)printf("%lld\n",ans);
		else printf("-1\n");
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll geshu(ll a)
{
	int sum=0;
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=2;i<=n-1;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				flag=0;
				break;
			}
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("-1\n");
				return 0;
			}
		}
		if(geshu(ans)!=n)
		{
			printf("-1\n");
			return 0;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include <algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll mod=9223372034707292160;
const int maxn=2e5+5;
ll geshu(ll a)
{
	int sum=0;
	for(int i=1;i<=sqrt(a);i++)
	{
		if(a%i==0)
		{
			sum++;
			if(a/i!=i)sum++;
		}
	}
	return sum-2;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		ll a[500];
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		ll ans;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		ans=a[1]*a[n];
		int flag=1;
		for(int i=2;i<=n-1;i++)
		{
			if(ans%a[i]!=0)
			{
				printf("%lld\n",ans%a[i]);
				flag=0;
				return 0;
			}
		}
		if(geshu(ans)!=n)
		{
			flag=0;
			printf("-1\n");
			return 0;
		}
		if(flag)printf("%lld\n",ans);

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
const int M=1000005;
const ll inf=0x3f3f3f3fll;
const ll mod=998244353ll;
int n,m;
ll a[N];
ll cnt[M];
void build(int x){
	for(int i=2;i*i<=x;i++){
		ll k=0;
		while(x%i==0){
			k++;
			x/=i;
		}
		cnt[i]=max(cnt[i],k);
	}
	if(x>1) cnt[x]=max(cnt[x],1ll);
}
int main(){
	ios::sync_with_stdio(0);
	int i,j;
	int T;cin>>T;
	while(T--){
		cin>>n;
		ll mx=0;
		for(i=1;i<=n;i++){
			cin>>a[i];mx=max(mx,a[i]);
			build(a[i]);
		}
		ll k=1,o=0,f,ans=1;
		for(i=1;i<M;i++){
			if(cnt[i]){
				o++;f=i;
				k*=cnt[i]+1;
				while(cnt[i]--)
					ans*=i;
				cnt[i]=0;
			}
		}
		if(k==n+2){
			if(mx==ans) cout<<-1<<endl;
			else cout<<ans<<endl;
		}
		else if(k==n+1&&o==1) cout<<ans*f<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		long  a[305];
		for(int i=0;i<n;++i)
			cin>>a[i];
			sort(a,a+n);
			unsigned long long ans=1;
			ans*=a[0];
			ans*=a[n-1];
				bool flag=1;
				int ans2=1;
			if(n%2==1)	ans2=a[n/2];
			ans2*=a[n/2];
			if(ans2!=ans)	flag=0;
			for(int i=0;i<n;++i)
				if(ans%a[i]!=0) flag=0;
			if(flag) cout<<ans<<endl;
			else cout<<-1<<endl;
	}
	return 0;
 }


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
long long t,n,a[5010];
bool flag;
signed main()
{
	cin>>t;
	while(t--)
	{
		flag=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		if(a[1]<=1)
		{
			cout<<-1<<endl;
			continue;
		}
		long long ji=a[1]*a[n];
		/*for(int l=2,r=n-1;l<=r;l++,r--){
			if(a[l]*a[r]!=ji){
				puts("-1");
				flag=1;
				break;
			}
		}*/

		for(int i=2;i<=n/2;i++)
		{
			if(a[i]*a[n-i+1]!=ji)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
//			cout<<-1<<endl;
			continue;
		}
		int ji1=0;
		for(int i=1;i*i<=ji;i++)
		{
			if(i*i==ji)
			ji1++;
			else if(ji%i==0)
			ji1+=2;
		}
//		cout<<ji1<<endl;
		if(ji1-2!=n)
		{
			cout<<-1<<endl;
			continue;
		}
		else
		cout<<ji<<endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n,T;
ll a[10000010];

int main()
{
    scanf("%d",&T);
    while( T -- )
    {
        scanf("%d",&n);
        for ( int i = 0; i < n; i++ )
        {
            scanf("%lld",&a[i]);
        }
        sort( a,a+n );
        ll ans = a[0] * a[n-1];
        ll q = sqrt(ans);
        int cur = 0;
        for ( int i = 2; i <= q; i++ )
        {
            if ( ans % i == 0 )
            {
                if ( a[cur] != i || a[cur] * a[n-cur-1] != ans )
                {
                    ans = -1;
                    break;
                }
                ++ cur;
            }
        }
        q = ( n + 1 ) / 2;
        for ( int i = cur; i < q; i++ )
        {
            if ( a[i] * a[n-i-1] != ans)
            {
                ans = -1; break;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll d[310];
map<ll,bool> mp;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		mp.clear();
		for(int i=0;i<n;i++){
			cin>>d[i];
			mp[d[i]]=1;
		}
		sort(d,d+n);
		ll mx=d[0]*d[n-1];
		bool flag=0;
		for(int i=1;i<n-1;i++){
			if(d[i]*d[n-1-i]!=mx)flag=1;
		}
		for(ll i=2;i*i<=mx;i++){
			if(mx%i==0&&(!mp[i]||!mp[mx/i]))flag=1;
		}
		if(flag)cout<<-1<<endl;
		else cout<<mx<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
long long t,n,a[1010],ji1;
bool flag;
signed main()
{
	cin>>t;
	while(t--)
	{
		ji1=0;
		flag=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		long long ji=a[1]*a[n];
		for(int i=2;i<=n/2;i++)
		{
			if(a[i]*a[n-i+1]!=ji)
			{
				flag=1;
				break;
			}
		}
		for(int i=1;i*i<=ji;i++)
		{
			if(i*i==ji)
			ji1++;
			else if(ji%i==0)
			ji1+=2;
		}
//		cout<<ji1<<endl;
		if(ji1-2!=n)
		flag=1;
		if(flag)
		{
			cout<<-1<<endl;
			continue;
		}
		cout<<ji<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd ch=getchar()
inline ll read()
{
	ll x=0;char dd;bool f=false;
	while(!isdigit(ch))f|=ch=='-',dd;
	while(isdigit(ch))x=(x<<1)+(x<<3)+ch-48,dd;
	return f?-x:x;
}
#undef dd
void write(ll x)
{
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);
	putchar(x%10+48);
}
#define writeln(x) (write(x),putchar('\n'))
#define writesp(x) (write(x),putchar(' '))

ll T,n,A[10005];
int anss(ll in){
	int up=floor(sqrt(in)),res=0;
	for(int i=2;i<=up;i++)
	if(in%i==0)res+=2;
	if(up*up==in)res--;
	return res;
}
int main(){
	T=read();
	while(T--){
		n=read();
		memset(A,0,sizeof(A));
		for(int i=1;i<=n;i++)A[i]=read();
		sort(A+1,A+1+n);
		ll i=1,j=n,la=A[1]*A[n];bool flag=true;
		while(i<=j){
			if(A[i]*A[j]!=la){flag=false;break;}
			i++;j--;
		}
		if(flag&&anss(la)==n)writeln(la);else writeln(-1);
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll d[310];
map<ll,bool> mp;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		mp.clear();
		for(int i=0;i<n;i++){
			cin>>d[i];
			mp[d[i]]=1;
		}
		sort(d,d+n);
		ll mx=d[0]*d[n-1];
		bool flag=0;
		for(int i=1;i<n-1;i++){
			if(d[i]*d[n-1-i]!=mx)flag=1;
		}
		for(int i=2;i*i<=mx;i++){
			if(mx%i==0&&(!mp[i]||!mp[mx/i]))flag=1;
		}
		if(flag)cout<<-1<<endl;
		else cout<<mx<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
const int maxn = 305;
int n, T;
int main() {
	cin >> T;
	while(T--) {
		std::vector<int> a;
		cin >> n;
		if(n % 2) {
			for(int i = 1; i <= n; i++) {
				int temp; cin >> temp;
				a.push_back(temp);
				if(i == (n + 1) / 2) {
					a.push_back(temp);
				}
			}
		} else {
			for(int i = 1; i <= n; i++) {
				int temp; cin >> temp;
				a.push_back(temp);
			}
		}
		std::sort(a.begin(), a.end());
		cout << 1ll * a[0] * a[a.size() - 1] << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e6;
int t,n;
ll a[305],pas,x,xx,cnt,sum;
int ck[maxn];
ll prime[80000],num;//78498个质数
void init()
{
	for(int i=2;i<maxn;i++)
	{
		if(!ck[i])
		{
			for(int j=i*2;j<maxn;j+=i)
			{
				ck[j]=i;
			}
			prime[++num]=i;
		}
	}
}
int main()
{
	init();
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		sort(a+1,a+n+1);
		pas=1;
		for(int i=2;i<=n-1;i++)
		{
			if(a[i]*a[n-i+1]!=a[i-1]*a[n-(i-1)+1])
			{
				pas=0;
				break;
			}
		}
		if(!pas)
		{
			cout<<-1<<endl;
			continue;
		}
		x=a[1]*a[n];
		xx=x;
		sum=1;
		for(int i=1;i<=num;i++)
		{
			if(prime[i]>sqrt(x)+1)
				break;
			cnt=0;
			while(xx%prime[i]==0)
			{
				cnt++;
				xx/=prime[i];
			}
			sum*=cnt+1;
		}
		if(sum-2==n)
			cout<<x<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
long long t,n,a[5010];
bool flag;
signed main()
{
	cin>>t;
	while(t--)
	{
		flag=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		if(a[1]<=1)
		{
			cout<<-1<<endl;
			continue;
		}
		long long ji=a[1]*a[n];
		/*for(int l=2,r=n-1;l<=r;l++,r--){
			if(a[l]*a[r]!=ji){
				puts("-1");
				flag=1;
				break;
			}
		}*/
		for(int i=2;i<=n/2+1;i++)
		{
			if(a[i]*a[n-i+1]!=ji)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			cout<<-1<<endl;
			continue;
		}
		int ji1=0;
		for(int i=1;i*i<=ji;i++)
		{
			if(i*i==ji)
			ji1++;
			else if(ji%i==0)
			ji1+=2;
		}
//		cout<<ji1<<endl;
		if(ji1-2!=n)
		{
			cout<<-1<<endl;
			continue;
		}
		else
		cout<<ji<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
const long long N=301;
long long T,d[N],n;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		bool ed=false;
		scanf("%d",&n);
		for(long long i=1;i<=n;i++)
			scanf("%d",&d[i]);
		sort(d+1,d+1+n);
		long long t=d[1]*d[n];
		for(long long i=2,j=n-1;i<j;i++,j--)
		{
			if(d[i]*d[j]!=t)
			{
				ed=true;
				break;
			}
		}
		if(n%2==1 && d[n/2+1]*d[n/2+1]!=t)
			ed=true;
		if(ed)
			printf("-1\n");
		else
			printf("%d\n",t);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int t;
int n,d[305];
int ans,ans1;
int cnt,ccur;
bool flag;
int cntp,prime[80005];
bool isprime(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0) return 0;
	}
	return 1;
}
int main(){
	for(int i=2;i<=1000000;i++){
		if(isprime(i)) prime[++cntp]=i;
	}
//	cout<<cntp<<endl;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&d[i]);
		sort(d+1,d+1+n);
		ans=d[1]*d[n];
		flag=1;
		for(int i=2;i<=(n+1)/2;i++){
			if(d[i]*d[n-i+1]!=ans){
				flag=0;
				break;
			}
		}
		if(flag){
			cnt=1;
			ans1=ans;
			for(int i=1;i<=cntp;i++){
				if(ans1==1) break;
				ccur=0;
				while(ans1%prime[i]==0){
					ans1/=prime[i];
					ccur+=1;
				}
				cnt*=ccur+1;
			}
			if(cnt-2!=n) flag=0;
		}
		if(!flag) printf("-1\n");
		else printf("%d\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		long  a[305];
		for(int i=0;i<n;++i)
			cin>>a[i];
			sort(a,a+n);
			unsigned long long ans=1;
			ans*=a[0];
			ans*=a[n-1];
			bool flag=1;
			for(int i=0;i<n;++i)
				if(ans%a[i]!=0) flag=0;
			if(flag) cout<<ans<<endl;
			else cout<<-1<<endl;
	}
	return 0;
 }


#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

int t;
int n;
ll a[305];

void print(ll sum){
	int num=0;
	for(ll i=2;i*i<=sum;i++)
	if(sum%i==0){
		if(i*i!=sum)num+=2;
		else
		if(i*i==sum)num+=1;
	}
	if(num==n)printf("%lld\n",sum);
	else printf("-1\n");
}

int main(void){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
		sort(a+1,a+1+n);
		if(a[1]==1){
			printf("-1\n");
			break;
		}
		int l=1,r=n;
		ll sum=a[l]*a[r];
		int tmp=1;
		while(l<=r){
			if(l!=r){
				if(a[l]*a[r]!=sum){
					tmp=0;
					break;
				}
			}
			if(l==r){
				if(a[l]*a[l]!=sum){
					tmp=0;
					break;
				}
			}
			l++;
			r--;
		}
		if(tmp==1)print(sum);
		else printf("-1\n");
	}
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
long long t,n,a[5010];
bool flag;
signed main()
{
	cin>>t;
	while(t--)
	{
		flag=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		if(a[1]<=1)
		{
			cout<<-1<<enl;
			continue;
		}
		long long ji=a[1]*a[n];
		for(int i=2;i<=n/2;i++)
		{
			if(a[i]*a[n-i+1]!=ji)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			cout<<-1<<endl;
			continue;
		}
		int ji1=0;
		for(int i=1;i*i<=ji;i++)
		{
			if(i*i==ji)
			ji1++;
			else if(ji%i==0)
			ji1+=2;
		}
//		cout<<ji1<<endl;
		if(ji1-2!=n)
		{
			cout<<-1<<endl;
			continue;
		}
		else
		cout<<ji<<endl;
	}
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
using namespace std;
const int INF = 0x3f3f3f3f;
long long n,m,t;
long long a[50005];
int main()
{
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld",&n);
		long long i;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+1+n);
		long long x=a[1]*a[n];
		long long p=0;
		for(i=2;i<n;i++)
		{
			if(x%a[i]!=0)
			{
				printf("-1\n");
				p=1;
				break;
			}
		}
		if(p==1)
		{
			continue;
		}
		long long ans=0;
		for(i=2;i<=sqrt(x);i++)
		{
			if(i*i==x)
			{
				ans++;
			}
			else if(x%i==0)
			{
				ans+=2;
			}
		}
		if(ans!=n)
		{
			printf("-1\n");
		}
		else
		{
			printf("%lld\n",x);
		}
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,n;
long long d[305],ans;
int main()
{
    cin>>t;
    while(t--)
    {
    	cin>>n;
    	for(int i=1;i<=n;i++) cin>>d[i];
    	sort(d+1,d+n+1);
    	ans=d[1]*d[n];
    	for(int i=2;i<n;i++)
    	if(ans%d[i])
		{
			ans=-1; break;
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[305];
		for(int i=0;i<n;++i)
			cin>>a[i];
			sort(a,a+n);
			int ans=1;
			ans=a[0]*a[n-1];
			bool flag=1;
			for(int i=0;i<n;++i)
				if(ans%a[i]!=0) flag=0;
			if(flag) cout<<ans<<endl;
			else cout<<-1<<endl;
	}
	return 0;
 }


#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const int N=317;
ll a[N];
ll num[N];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,hh=0,flag=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++) scanf("%lld",&a[i]);
		sort(a,a+n);
		int i=0,j=n-1;
		while(i<=j)
		{
			num[hh++]=a[i]*a[j];
			i++;j--;
		}
		for(int i=1;i<hh;i++)
		{
			if(num[i]!=num[i-1])
			{
				printf("-1\n");
				flag=1;
				break;
			}
		}
		if(flag==0) printf("%lld\n",num[0]);
	}
}


#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
typedef long long ll;
template <typename T>
inline void read(T& x) {
    T res = 0, flag = 1;
    char ch;
    ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        res = res * 10 + ch - 48;
        ch = getchar();
    }
    x = res * flag;
}
const int N = 300 + 2;
int t, n, x;
std::vector <ll> d, c;
int main() {
    read(t);
    while(t--) {
        read(n);
        d.clear();
        c.clear();
        for(int i = 0; i < n; ++i)
           read(x), d.push_back(x);
        std::sort(d.begin(), d.end());
        ll x = d[0] * d[n - 1], s = sqrt(x);
        for(ll i = 2; i <= s; ++i) {
            if(!(x % i))
                c.push_back(i), c.push_back(x / i);
            if(i * i == x)
                c.pop_back();
        }
        // printf("=%lld\n", x);
        // for(auto i: c)
        //     printf("*%d\n", i);
        if(c.size() != n) {
            puts("-1");
            continue;
        }
        std::sort(c.begin(), c.end());
        printf("%lld\n", (d == c) ? x : -1);
    }
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<long long> v;
		for(int i=0;i<n;i++)
		{
			int a;
			cin>>a;
			v.push_back(a);
		}
		sort(v.begin(),v.end());

		int ans=v[0]*v[n-1];
		int flag1=1;
		int i=0,j=n-1;
		while(i<=j)
		{
			if(v[i]*v[j]!=ans)
			{
				cout<<"-1"<<endl;
				flag1=0;
				break;
			}
			i++; j--;
		}

		if(flag1)
		{
			int flag2=1;
			vector<int> w;
			for(int i=2;i<=sqrt(ans);i++)
			{
				if(ans%i==0)
				{
					w.push_back(i);
					if(i*i!=ans) w.push_back(ans/i);
				}
			}
			sort(w.begin(),w.end());
			for(int i=0;i<n;i++)
			{
				if(v[i]!=w[i])
				{
					cout<<"-1"<<endl;
					flag2=0;
					break;
				}
			}
			if(flag2) cout<<ans<<endl;
		}
	}
	return 0;
}


#include <cstdio>
#include <cctype>
#include <algorithm>

#define int long long

const int MAXN = 300;

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-') f = -1; ch = getchar();}
	while(isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	return x * f;
}

int a[MAXN + 5];
int b[MAXN + 5];

signed main() {
	int t = read();
	while(t--) {
		int n = read();
		for(int i = 1; i <= n; i++)
			a[i] = read();
		std::sort(a + 1, a + n + 1);
		int s = a[1] * a[n];
		int cnt = 0, k;
		bool f = false;
		for(int i = 2; i * i <= s; i++) {
			if(s % i == 0) {
				if(cnt == MAXN) {
					puts("-1");
					f = true;
					break;
				}
				b[++cnt] = i;
				if(cnt == MAXN) {
					puts("-1");
					f = true;
					break;
				}
				b[++cnt] = s / i;
			}
			k = i;
		}
		if(f)
			continue;
		if(k * k == s)
			--cnt;
		std::sort(b + 1, b + cnt + 1);
		if(n != cnt) {
			puts("-1");
			continue;
		}
		bool flag = true;
		for(int i = 1; i <= n; i++)
			if(a[i] != b[i]) {
				flag = false;
				break;
			}
		printf("%lld\n", flag ? s : -1);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int t,n,a[305];

int pnum(long long x){
	int ans=0;
	for(int i=2;i<x;i++){
		if(x%i==0) ans++;
	}
	return ans;
}

int main(){
	cin>>t;
	while(t--){
		cin>>n;
		bool f=1;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		sort(a+1,a+n+1);
		long long x=a[1]*a[n],y;
		for(int i=1;i<=(n+1)/2;i++){
			y=a[i]*a[n-i+1];
			if(x!=y){
				f=0;
				break;
			}
			x=y;
		}
		if(f==0){
			cout<<-1<<endl;
			continue;
		}
		int num=pnum(x);
		if(num!=n){
			cout<<-1<<endl;
			continue;
		}
		cout<<x<<endl;
	}
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int T, n, temp, ans, MAX, a[305], note[305];
int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
long long gbs(int a, int b) {
	return a * b / gcd(a, b);
}
int main() {
	cin >> T;
	for (int t = 1; t <= T; t++) {
		MAX = 0;
		cin >> n;
		for (int i = 1; i <= n; i++) {
		 	cin >> a[i];
		 	MAX = max(MAX, a[i]);
			if (i == 1) temp = a[i];
			else temp = gbs(temp, a[i]);
		}
		ans = temp;
		if (ans == MAX)	ans = temp * 2;
		int cnt = 0;
		for (int i = 2; i < sqrt(ans); i++) {
			if (ans % i == 0) {
				note[++cnt] = i;
				note[++cnt] = ans / i;
			}
		}
		if (sqrt(ans) * sqrt(ans) == ans)
			note[++cnt] = sqrt(ans);
		if (cnt != n) cout << "-1" << endl;
		else cout << ans << endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
#define N 2000005
int b[N];
int check (ll a)
{
    ll i;
    for(i=2; i<=sqrt(a); i++)
    {
        if(a%i==0&&(b[i]!=1||b[a/i]!=1))
            return 0;
    }
    return 1;
}
int main()
{
    int n,i,j,k=1;
    int T,unit;
    int x,z,y;
    int m;
    char c;
    int flag=0;
    int sum=0;
    int a[10000];
    scanf("%d",&T);
    while(T--)
    {
        for(i=0;i<N;i++)
            b[i]=0;
        ll ans=1;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            b[a[i]]=1;
        }
        sort(a,a+n);
        ans=a[0]*a[n-1];
        if(!check(ans))
            ans=-1;
        for(i=1; i<n; i++)
            if(ans!=a[i]*a[n-1-i])
            {
                ans=-1;
                break;
            }
        printf("%lld\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int p[1000010],cnt;
bool v[1000010];
int t;
int d[1000010],n,ans=1;
void prime()
{
	for(int i=2;i<=1000000;i++)
	{
		if(!v[i])
		{
			p[++cnt]=i;
			for(int j=1;i*p[j]<=1000000;j++){
				v[p[j]*i]=1;
				if(i%p[j]==0)
				    break;
			}

		}
	}
}
void work()
{
	memset(d,0,sizeof(d));
	ans=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	sort(d+1,d+1+n);
	int i=1,j=n;
	int ji=d[i]*d[j];
	while(i<=j)
	{
		if(ji!=d[i]*d[j])
		{
			cout<<"-1";
			return;
		}
		i++;
		j--;
	}
	int pi=ji;
	for(int i=1;i<=cnt&&pi>=p[i];i++)
	{
		int k=0;
		while(pi%p[i]==0)
		{
			k++;
			pi/=p[i];
		}
		ans*=(k+1);
	}
	if(pi>1)
		ans*=2;
	if(ans-2==n)
	{
		cout<<ji<<endl;
	}
	else
	{
		cout<<"-1";
	}
}
int main()
{
	prime();
	cin>>t;
	for(;t>0;t--)
		work();
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 305
//排序后扫半个数组，复杂度大概在o(t*(nlogn+n)),是一定能过的
//ps.科普：c++的sort时间复杂度在n*log(2)n简称n*logn
//sort比qsort更优一些
int a[N];
int ap[N];//appear记录出现过的数字
int main(){
	int t;
	cin>>t;
	while(t--){
		memset(ap,0,sizeof(ap));
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			//为了防止出现重复的数，我也不知道这里会不会卡
			ap[a[i]]=1;
		}
		sort(a+1,a+1+n);
		long long ans=a[1]*a[n];
		//这里可以有一个直接验证这个ans的所有因数是否都出现过的步骤，但我觉得省略也不会怎样
		for(int i=2;i<=sqrt(ans);i++){
			if(ans % i==0 && (ap[i]==0 || ap[ans/i]==0)){
				ans=-1;
			}
		}
		for(int i=2;i<n;i++){
			if(ans==-1) break;
			if(a[i]*a[n-i+1]!=a[i-1]*a[n-i+2]){
				ans=-1;
				break;
			}
		}
		printf("%lld\n",ans);
	}
}


#include <iostream>
#include <map>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
	ios::sync_with_stdio(false);
	LL t, n, i;
	LL a[500], x;
	cin >> t;
	while (t--)
	{
		int f = 1;
		cin >> n;
		for (i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n);

		x = a[0] * a[n - 1];
		for (i = 0; i < n; i++)
			if (x%a[i] != 0)
				f = 0;
		if (f)
		{
			LL k = sqrt(x) + 1, c = 0;
			for (i = 2; i < k; i++)
				if (x%i == 0)
				{
					if (i != x / i)
						c += 2;
					else
						c += 1;
				}
			if (c == n)
				cout << x << endl;
			else
				cout << -1 << endl;
		}
		else
			cout << -1 << endl;

	}
}


#include <cstdio>
#include <map>
using namespace std;

int t , n , a[ 305 ];
map< int , bool > Map;

long long Gcd( long long a , long long b ) {
	return !b ? a : Gcd( b , a % b );
}

int main( ) {
	scanf("%d",&t);
	while( t -- ) {
		Map.clear();
		long long Ans = 1;

		scanf("%d",&n);
		for( int i = 1 ; i <= n ; i ++ ) {
			scanf("%d",&a[ i ]);
			Ans = Ans * a[ i ] / Gcd( Ans , a[ i ] );
			Map[ a[ i ] ] = 1;
		}
		if( Map[ Ans ] ) Ans *= 2;
		for( long long i = 2 ; i * i <= Ans ; i ++ ) {
			if( Ans % i == 0 && ( !Map[ i ] || !Map[ Ans / i ] ) ) {
				printf("%d\n",-1);
				goto there;
			}
		}
		printf("%lld\n",Ans);
		there:;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
long long t,n,a[5010];
bool flag;
signed main()
{
	cin>>t;
	while(t--)
	{
		flag=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		/*sort(a+1,a+n+1);
		if(a[1]<=1){puts("-1");continue;}
		long long ji=a[1]*a[n];*/

		sort(a+1,a+1+n);
		if(a[1]<=1)
		{
			cout<<-1<<endl;
			continue;
		}
		for(int l=2,r=n-1;l<=r;l++,r--){
			if(a[l]*a[r]!=ji){
				puts("-1");
				flag=1;
				break;
			}
		}
		/*long long ji=a[1]*a[n];
		for(int i=2;i<=n/2;i++)
		{
			if(a[i]*a[n-i+1]!=ji)
			{
				flag=1;
				break;
			}
		}*/
		if(flag)
		{
//			cout<<-1<<endl;
			continue;
		}
		int ji1=0;
		for(int i=1;i*i<=ji;i++)
		{
			if(i*i==ji)
			ji1++;
			else if(ji%i==0)
			ji1+=2;
		}
//		cout<<ji1<<endl;
		if(ji1-2!=n)
		{
			cout<<-1<<endl;
			continue;
		}
		else
		cout<<ji<<endl;
	}
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
int ds(ll n)
{
    int k=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
            k+=2;
        if(i*i==n)
            k--;
    }
    return k;
}
int main()
{
    int t;
    ll a[3100];
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        ll ans=a[0]*a[n-1];
        if(ds(ans)!=n)
        {
            ans=-1;
        }
        else
        {

            for(int i=0;i<n;i++)
            {
                if(ans%a[i])
                {
                    ans=-1;
                    break;
                }
            }
        }
        if(ans!=-1){
        for(int i=0;i<n;i++)
        {
            if(a[i]*a[n-i-1]!=ans)
            {
                ans=-1;
                break;
            }
        }}
        printf("%lld\n",ans);
    }
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<long long> v;
		for(int i=0;i<n;i++)
		{
			int a;
			cin>>a;
			v.push_back(a);
		}
		sort(v.begin(),v.end());

		long long ans=v[0]*v[n-1];
		//int flag1=1;
		int i=0,j=n-1;
		while(i<=j)
		{
			if(v[i]*v[j]!=ans)
			{
				cout<<"-1"<<endl;
				//flag1=0;
				//break;
				return 0;
			}
			i++; j--;
		}

		//if(flag1)
		//{
			//int flag2=1;
			vector<int> w;
			for(int i=2;i<=sqrt(ans);i++)
			{
				if(ans%i==0)
				{
					w.push_back(i);
					if(i*i!=ans) w.push_back(ans/i);
				}
			}
			sort(w.begin(),w.end());
			for(int i=0;i<n;i++)
			{
				if(v[i]!=w[i])
				{
					cout<<"-1"<<endl;
					return 0;
					//flag2=0;
					//break;
				}
			}
			//if(flag2)
			cout<<ans<<endl;
		//}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[305];
		for(int i=0;i<n;++i)
			cin>>a[i];
			sort(a,a+n);
			long long ans=1;
			ans=a[0]*a[n-1];
			bool flag=1;
			for(int i=0;i<n;++i)
				if(ans%a[i]!=0) flag=0;
			if(flag) cout<<ans<<endl;
			else cout<<-1<<endl;
	}
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
long long ans,s[301],num[301],T,n;
int main()
{
	cin>>T;
    while(T--)
    {	int pos=0,flag=0;
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>s[i];
    	sort(s+1,s+1+n);
    	ans=s[1]*s[n];
    	for(int i=2;i<=sqrt(ans);i++)
    		if(ans%i==0){
    			num[++pos]=i;
    			if(i!=ans/i)
    			num[++pos]=ans/i;
			}
		if(pos!=n)flag=1;
		else{
		sort(num+1,num+1+n);
		for(int i=1;i<=n;i++)
		if(num[i]!=s[i]){flag=1;break;}
		}
    	if(flag)cout<<-1<<endl;
    	else cout<<ans<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int t,n,a[305];

int pnum(long long x){
	int ans=0;
	for(int i=2;i*i<=x;i++){
		if(x%i==0) ans+=2;
		if(x/i==i) ans--;
	}
	return ans;
}

int main(){
	cin>>t;
	while(t--){
		cin>>n;
		bool f=1;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		sort(a+1,a+n+1);
		long long x=a[1]*a[n],y;
		for(int i=1;i<=(n+1)/2;i++){
			y=a[i]*a[n-i+1];
			if(x!=y){
				f=0;
				break;
			}
			x=y;
		}
		if(f==0){
			cout<<-1<<endl;
			break;
		}
		int num=pnum(x);
		if(num!=n){
			cout<<-1<<endl;
			break;
		}
		cout<<x<<endl;
	}
	return 0;
}


#include <cmath>
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

template <typename T>
T Max(T x, T y) {return x > y ? x : y;}

template <typename T>
T Min(T x, T y) {return x < y ? x : y;}

template <typename T>
T Fabs(T x) {return x > 0 ? x : -x;}

#define LL long long

const int N = 305;

LL a[N];
int t, n;
bool vis[1000005];

int main() {
    scanf("%d", &t);
    while(t --) {
        memset(vis, 0, sizeof vis);
        bool f = 0;
        scanf("%d", &n);
        for(int i = 1; i <= n; i ++) {
            scanf("%lld", &a[i]);
            vis[a[i]] = 1;
        }
        sort(a + 1, a + 1 + n);
        for(int i = 2; i <= (n + 1) / 2; i ++)
            if(a[i] * a[n - i + 1] != a[i - 1] * a[n - i + 2]) {
                f = 1;
                break;
            }
        if(f) {
            puts("-1");
            continue;
        }
        LL ans = a[1] * a[n];
        for(LL i = 2; i <= sqrt(ans); i ++) {
            if(ans % i != 0) continue;
            if(ans % i == 0 && vis[i] && vis[ans / i]) continue;
            f = 1;
            break;
        }
        if(f) puts("-1");
        else printf("%lld\n", ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define ll unsigned  long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+100;
const ll mod = 998244353 ;
ll a[maxn];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            scanf("%lld",&a[i]);
        }
        sort(a+1,a+n+1);
        ll ans=a[1]*a[n];
        int flag=1;
        for(int i=1; i<=n; i++)
        {
            if(ans%a[i]!=0)
                flag=0;
        }
        if(!flag)
        {
            printf("-1\n");
        }
        else
        {
            ll tmp=(int)sqrt(ans);
            int cnt=0;
            for(ll i=2; i<=tmp; i++)
            {
                if(ans%i==0)
                {
                    cnt++;
                    if(ans/i!=i)cnt++;// 如果是9=3*3这类的，应该算一个
                }
            }
        //    cout<<cnt<<endl;
            if(cnt==n)
                printf("%lld\n",ans);
                else printf("-1\n");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long N=310;
const long long MAXN=1000001;
long long n;
long long d[N];
long long dig[200000];
long long minn=1;
long long count0;
long long maxs,mins;
long long need[200000];
bool nis_prime[MAXN];
long long size;
void creat()
{
    for(long long k=2;k<=MAXN;k++)
    {
        if(nis_prime[k])
            continue;
        need[size++]=k;
        for(long long i=2;i*k<=MAXN;i++)
            nis_prime[i*k]=true;
    }
}
int main()
{
    long long opt;
    scanf("%lld",&opt);
    creat();
    while(opt--)
    {
        memset(dig,0,sizeof(dig));
        minn=1,count0=0;
        maxs=0,mins=999999999;
        scanf("%d",&n);
        for(long long k=1;k<=n;k++)
        {
            long long a;
            scanf("%d",&d[k]);
            a=d[k];
            for(long long i=0;i<size;i++)
            {
                if(need[i]>a)
                    break;
                long long ls=0;
                while(a && a%need[i]==0)
                {
                    a/=need[i];
                    ls++;
                }
                dig[i]=max(dig[i],ls);
            }
            maxs=max(maxs,d[k]),mins=min(mins,d[k]);
        }
        for(long long k=0;k<size;k++)
            minn*=pow(need[k],dig[k]);
        if(minn==maxs)
            minn*=mins;
        long long s=sqrt(minn);
        for(long long k=2;k<=s;k++)
            if(minn%k==0)
                if(minn/k!=k)
                    count0+=2;
                else
                    count0+=1;
        if(count0==n)
            printf("%lld\n",minn);
        else
            printf("-1\n");
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int T, n, temp, ans, MAX, MIN, a[305], note[305];
int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
long long gbs(int a, int b) {
	return a * b / gcd(a, b);
}
int main() {
	cin >> T;
	for (int t = 1; t <= T; t++) {
		MAX = 0;
		cin >> n;
		for (int i = 1; i <= n; i++) {
		 	cin >> a[i];
		 	MAX = max(MAX, a[i]);
			if (i == 1) { temp = a[i]; MIN = a[i]; }
			else { temp = gbs(temp, a[i]); MIN = min(MIN, a[i]); }
		}
		ans = temp;
		if (ans == MAX)	ans = temp * MIN;
		int cnt = 0;
		for (int i = 2; i < sqrt(ans); i++) {
			if (ans % i == 0) {
				note[++cnt] = i;
				note[++cnt] = ans / i;
			}
		}
		if (sqrt(ans) * sqrt(ans) == ans)
			note[++cnt] = sqrt(ans);
		if (cnt != n) cout << "-1" << endl;
		else cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int p[1000010],cnt;
bool v[1000010];
int t;
int d[1000010],n,ans=1;
void prime()
{
	for(int i=2;i<=1000000;i++)
	{
		if(!v[i])
		{
			p[++cnt]=i;
			for(int j=1;i*p[j]<=1000000;j++){
				v[p[j]*i]=1;
				if(i%p[j])
			}

		}
	}
}
void work()
{
	memset(d,0,sizeof(d));
	ans=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	sort(d+1,d+1+n);
	int i=1,j=n;
	int ji=d[i]*d[j];
	while(i<=j)
	{
		if(ji!=d[i]*d[j])
		{
			cout<<"-1";
			return;
		}
		i++;
		j--;
	}
	int pi=ji;
	for(int i=1;i<=cnt&&pi>=p[i];i++)
	{
		int k=0;
		while(pi%p[i]==0)
		{
			k++;
			pi/=p[i];
		}
		ans*=(k+1);
	}
	if(d>1)
		ans*=2;
	if(ans-2==n)
	{
		cout<<ji<<endl;
	}
	else
	{
		cout<<"-1";
	}
}
int main()
{
	prime();
	cin>>t;
	for(;t>0;t--)
		work();
	return 0;
}


#include <iostream>
#include <algorithm>
#include<string.h>
#include<set>
#include<math.h>
#include<stdio.h>
#define ll long long
using namespace std;
int main()
{ll nn,kk=0;
scanf("%lld",&nn);
while(kk<nn)
{
    ll n,k=0,a[305],z,q=2,c=0;
    scanf("%lld",&n);
    while(k<n)
    {
        scanf("%lld",&a[k]);
        k++;
    }
    sort(a,a+n);
    z=a[0]*a[n-1];
    k=0;
    while(q<=sqrt((double)z))
    {
        if(z%q==0)
        {
            if(a[k]!=q||a[n-1-k]!=z/q)
            {
                c=1;
                break;
            }
            k++;
        }
        q++;
    }
    if(c==1)
    {
        printf("-1\n");
        kk++;
        continue;
    }
    k--;
    if(n-1-k-k>1)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n",z);
    }
    kk++;
}
return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 305
//排序后扫半个数组，复杂度大概在o(t*(nlogn+n)),是一定能过的
//ps.科普：c++的sort时间复杂度在n*log(2)n简称n*logn
//sort比qsort更优一些
long long a[N];
int ap[1000005];//appear记录出现过的数字
int main(){
	int t;
	cin>>t;
	while(t--){
		memset(ap,0,sizeof(ap));
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			//为了防止出现重复的数，我也不知道这里会不会卡
			ap[a[i]]=1;
		}
		sort(a+1,a+1+n);
		long long ans=a[1]*a[n];
		//这里可以有一个直接验证这个ans的所有因数是否都出现过的步骤，但我觉得省略也不会怎样
		for(int i=2;i<=sqrt(ans);i++){
			if(ans % i==0 && (ap[i]==0 || ap[ans/i]==0)){
				ans=-1;
				break;
			}
		}
		for(int i=2;i<n;i++){
			if(ans==-1) break;
			if(a[i]*a[n-i+1]!=a[i-1]*a[n-i+2]){
				ans=-1;
				break;
			}
		}
		printf("%lld\n",ans);
	}
}


#include <iostream>
#include <map>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
	ios::sync_with_stdio(false);
	LL t, n, i;
	LL a[500], x;
	cin >> t;
	while (t--)
	{
		int f = 0;
		cin >> n;
		for (i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n);
		if (n > 1)
		{
			x = a[0] * a[n - 1];
			for (i = 0; i < n; i++)
				if (x%a[i] != 0)
					f = 1;
			if (!f)
			{
				int k = sqrt(x) + 1, c = 0;
				for (i = 2; i < k;i++)
					if (x%i == 0)
					{
						if (i != x / i)
							c++;
						else
							c += 2;
					}
				if (c == n)
					cout << x << endl;
				else
					cout << -1 << endl;
			}
			else
				cout << -1 << endl;
		}
		else
			cout << a[0] << endl;
	}
}


#include<bits/stdc++.h>
#define REP(i,first,last) for(int i=first;i<=last;++i)
#define DOW(i,first,last) for(int i=first;i>=last;--i)
using namespace std;
#define MAXN 100007
int N,M,T;
long long a[MAXN];
long long sum[MAXN];
long long p[MAXN];
int cnt=0;
long long Gcd(long long a,long long b)
{
	if(!b)
	{
		return a;
	}
	return Gcd(b,a%b);
}
void work()
{
	REP(i,1,2000)
	{
		sum[i]=0;
	}
	scanf("%d",&N);
	long long num=1;
	REP(i,1,N)
	{
		scanf("%lld",&a[i]);
	}
	long long gcd;
	REP(i,1,N)
	{
		gcd=Gcd(num,a[i]);
		num*=a[i]/gcd;
	}
	cnt=0;
	long long n=num;
	REP(i,2,1000)
	{
		if(n%i==0)
		{
			p[++cnt]=i;
			while(n%i==0)
			{
				sum[i]++;
				n/=i;
			}
		}
	}
	long long f=1;
	REP(i,1,1000)
	{
		f*=sum[i]+1;
	}
	if(f-2==N)
	{
		bool check=1;
		REP(i,1,N)
		{
			if(a[i]==num)
			{
				check=0;
				break;
			}
		}
		if(check)
		{
			printf("%lld\n",num);
			return;
		}
	}
	long long now;
	REP(i,1,cnt)
	{
		now=f/(sum[p[i]]+1);
		now*=sum[p[i]]+2;
		if(now-2==N)
		{
			printf("%lld\n",num*p[i]);
			return;
		}
	}
	printf("-1\n");
}
int main()
{
	scanf("%d",&T);
	REP(i,1,T)
	{
		work();
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll d[310];
map<ll,bool> mp;
bool isprime(ll x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0)return false;
	}
	return true;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		mp.clear();
		for(int i=0;i<n;i++){
			cin>>d[i];
			mp[d[i]]=1;
		}
		sort(d,d+n);
		ll mx=d[0]*d[n-1];
		if(n==1)mx=d[0];
		bool flag=0;
		for(int i=1;i<n-1;i++){
			if((i!=n-1-i&&d[i]*d[n-1-i]!=mx)||(i==n-1-i&&mx!=d[i]))flag=1;
		}
		if(mx==d[n-1]){
			for(int i=0;i<n;i++){
				if(isprime(d[i])){
					mx*=d[i];
					break;
				}
				if(i==n-1)flag=1;
			}
		}
		if(flag)cout<<-1<<endl;
		else cout<<mx<<endl;
	}
	return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const lli M = 1e6+5;
lli PRIME[M];
lli b[2*M];

void P()
{
    for(lli i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(lli j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int sumofFactors(int n)
{
    int ans = 1;

    for(int i = 2; i <= sqrt(n); i++){
        int c_s = 1, c_t = 1;

        while(n%i == 0){
            n = n / i;
            c_t *= i;
            c_s += c_t;
        }
        ans *= c_s;
    }

    if(n >= 2) ans *= (1 + n);

    return ans;
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    lli t, n;

    cin >> t;

    while(t--){
        cin >> n;

       // memset(b, 0, sizeof(b));

        lli a[n+5], val, cnt = 0, d1, d2, sum = 0;

        for(lli i = 0; i < n; i++) {cin >> a[i]; sum += a[i];}

        sort(a, a+n);

        if(n == 1){
            val = a[0]*a[0];
            if(PRIME[a[0]] == 0) cout << val << endl;
            else cout << -1 << endl;
            continue;
        }
        else val = a[0] * a[n-1];

        lli sum2 = sumofFactors(val);
        //cout << sum2 << " " << sum << endl;
        sum2 -= (val+1);

        if(sum2 == sum) cout << val << endl;
        else cout << -1 << endl;

        //cout << val << endl;

//        for(int i = 1; i*i <= val; i++){
//            if(i == 1 || i == val) continue;
//
//            if(val%i == 0){
//                d1 = i; d2 = val/i;
//                if(b[d1] == 0 || b[d2] == 0) {break;}
//                else if(d1 != d2) cnt += 2;
//                else cnt++;
//            }
//        }
//
//        if(cnt == n) cout << val << endl;
//        else cout << -1 << endl;
//
//        lli lcm = a[0], gcd, mul;
//
//        for(lli i = 1; i < n; i++){
//            mul = lcm * a[i];
//            gcd = __gcd(lcm, a[i]);
//
//            lcm = mul/gcd;
//        }
//        if(lcm == a[n-1]){
//            if(PRIME[lcm] == 0) cout << (lcm*lcm) << endl;
//            else cout << -1 << endl;
//        }
//        else cout << lcm << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const lli M = 1e6+5;
lli PRIME[M];
lli b[2*M];

void P()
{
    for(lli i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(lli j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    lli t, n;

    cin >> t;

    while(t--){
        cin >> n;

       // memset(b, 0, sizeof(b));

        lli a[n+5], val, cnt = 0, d1, d2;

        for(lli i = 0; i < n; i++) {cin >> a[i]; b[a[i]] = 1;}

        sort(a, a+n);

        if(n == 1){
            val = a[0]*a[0];
            if(PRIME[a[0]] == 0) cout << val << endl;
            else cout << -1 << endl;
            continue;
        }
        //else val = a[0] * a[n-1];

        //cout << val << endl;

//        for(int i = 1; i*i <= val; i++){
//            if(i == 1 || i == val) continue;
//
//            if(val%i == 0){
//                d1 = i; d2 = val/i;
//                if(b[d1] == 0 || b[d2] == 0) {break;}
//                else if(d1 != d2) cnt += 2;
//                else cnt++;
//            }
//        }
//
//        if(cnt == n) cout << val << endl;
//        else cout << -1 << endl;

        lli lcm = a[0], gcd, mul;

        for(lli i = 1; i < n; i++){
            mul = lcm * a[i];
            gcd = __gcd(lcm, a[i]);

            lcm = mul/gcd;
        }
        if(lcm == a[n-1]){
            if(PRIME[lcm] == 0) cout << (lcm*lcm) << endl;
            else cout << -1 << endl;
        }
        else cout << lcm << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const lli M = 1e6+5;
lli PRIME[M];
lli b[2*M];

void P()
{
    for(lli i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(lli j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    lli t, n;

    cin >> t;

    while(t--){
        cin >> n;

       // memset(b, 0, sizeof(b));

        lli a[n+5], val, cnt = 0, d1, d2;

        for(lli i = 0; i < n; i++) {cin >> a[i]; b[a[i]] = 1;}

        sort(a, a+n);

        if(n == 1){
            val = a[0]*a[0];
            if(PRIME[a[0]] == 0) cout << val << endl;
            else cout << -1 << endl;
            continue;
        }
        //else val = a[0] * a[n-1];

        //cout << val << endl;

//        for(int i = 1; i*i <= val; i++){
//            if(i == 1 || i == val) continue;
//
//            if(val%i == 0){
//                d1 = i; d2 = val/i;
//                if(b[d1] == 0 || b[d2] == 0) {break;}
//                else if(d1 != d2) cnt += 2;
//                else cnt++;
//            }
//        }
//
//        if(cnt == n) cout << val << endl;
//        else cout << -1 << endl;

        lli lcm = a[0], gcd, mul;

        for(lli i = 1; i < n; i++){
            mul = lcm * a[i];
            gcd = __gcd(lcm, a[i]);

            lcm = mul/gcd;
        }
        if(lcm == a[n-1]){
            if(PRIME[lcm] == 0) cout << (lcm*lcm) << endl;

            else cout << a[0] * a[n-1] << endl;
        }
        else cout << lcm << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const int M = 2e6+6;
int b[M];

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    int t, n;

    cin >> t;

    while(t--){
        cin >> n;

        memset(b, 0, sizeof(b));

        int a[n+5], val, cnt = 0, d1, d2;

        for(int i = 0; i < n; i++) {cin >> a[i]; b[a[i]] = 1;}

        sort(a, a+n);

        if(n == 1) val = a[0]*a[0];
        else val = a[0] * a[n-1];

        for(int i = 1; i*i <= val; i++){
            if(i == 1 || i == val) continue;

            if(val%i == 0){
                d1 = i; d2 = val/i;
                if(b[d1] == 0 || b[d2] == 0) {break;}
                else if(d1 != d2) cnt += 2;
                else cnt++;
            }
        }

        if(cnt == n) cout << val << endl;
        else cout << -1 << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const lli M = 1e6+5;
lli PRIME[M];
lli b[2*M];

void P()
{
    for(lli i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(lli j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    lli t, n;

    cin >> t;

    while(t--){
        cin >> n;

       // memset(b, 0, sizeof(b));

        lli a[n+5], val, cnt = 0, d1, d2;

        for(lli i = 0; i < n; i++) {cin >> a[i]; b[a[i]] = 1;}

        sort(a, a+n);

        if(n == 1){
            val = a[0]*a[0];
            if(PRIME[a[0]] == 0) cout << val << endl;
            else cout << -1 << endl;
            continue;
        }
        //else val = a[0] * a[n-1];

        //cout << val << endl;

//        for(int i = 1; i*i <= val; i++){
//            if(i == 1 || i == val) continue;
//
//            if(val%i == 0){
//                d1 = i; d2 = val/i;
//                if(b[d1] == 0 || b[d2] == 0) {break;}
//                else if(d1 != d2) cnt += 2;
//                else cnt++;
//            }
//        }
//
//        if(cnt == n) cout << val << endl;
//        else cout << -1 << endl;

        lli lcm = a[0], gcd, mul;

        for(lli i = 1; i < n; i++){
            mul = lcm * a[i];
            gcd = __gcd(lcm, a[i]);

            lcm = mul/gcd;
        }

        cout << lcm << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

int PRIME[1000000];

void P()
{
    for(int i = 2; i*i <= 1e6; i++){
        if(PRIME[i]){
            for(int j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

const int M = 2e6+6;
int b[M];

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    int t, n;

    cin >> t;

    while(t--){
        cin >> n;

        memset(b, 0, sizeof(b));

        int a[n+5], val, cnt = 0, d1, d2;

        for(int i = 0; i < n; i++) {cin >> a[i]; b[a[i]] = 1;}

        sort(a, a+n);

        if(n == 1){
            if(PRIME[a[0]] == 0) cout << a[0]*a[0] << endl;
            else cout << -1 << endl;
            continue;
        }
        else val = a[0] * a[n-1];

        for(int i = 1; i*i <= val; i++){
            if(i == 1 || i == val) continue;

            if(val%i == 0){
                d1 = i; d2 = val/i;
                if(b[d1] == 0 || b[d2] == 0) {break;}
                else if(d1 != d2) cnt += 2;
                else cnt++;
            }
        }

        if(cnt == n) cout << val << endl;
        else cout << -1 << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const int M = 1e6+5;
int PRIME[M];

void P()
{
    for(int i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(int j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    int t, n;

    cin >> t;

    while(t--){
        cin >> n;

       // memset(b, 0, sizeof(b));

        int a[n+5], val, cnt = 0, d1, d2;

        for(int i = 0; i < n; i++) cin >> a[i];

        sort(a, a+n);

        if(n == 1){
            val = a[0]*a[0];
            if(PRIME[a[0]] == 0) cout << val << endl;
            else cout << -1 << endl;
            continue;
        }
        else val = a[0] * a[n-1];

        cout << val << endl;

//        for(int i = 1; i*i <= val; i++){
//            if(i == 1 || i == val) continue;
//
//            if(val%i == 0){
//                d1 = i; d2 = val/i;
//                if(b[d1] == 0 || b[d2] == 0) {break;}
//                else if(d1 != d2) cnt += 2;
//                else cnt++;
//            }
//        }
//
//        if(cnt == n) cout << val << endl;
//        else cout << -1 << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const lli M = 1e6+5;
lli PRIME[M];
lli b[2*M];

void P()
{
    for(lli i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(lli j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int sumofFactors(int n)
{
    int ans = 1;

    for(int i = 2; i <= sqrt(n); i++){
        int c_s = 1, c_t = 1;

        while(n%i == 0){
            n = n / i;
            c_t *= i;
            c_s += c_t;
        }
        ans *= c_s;
    }

    if(n >= 2) ans *= (1 + n);

    return ans;
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    lli t, n;

    cin >> t;
    vector<lli> v;

    while(t--){
        v.clear();
        cin >> n;

       // memset(b, 0, sizeof(b));

        lli a[n+5], val, cnt = 0, d1, d2, sum = 0;

        for(lli i = 0; i < n; i++) {cin >> a[i]; sum += a[i];}

        sort(a, a+n);
        val = a[0] * a[n-1];

        //lli sum2 = sumofFactors(val);
        //cout << sum2 << " " << sum << endl;
//        sum2 -= (val+1);
//
//        if(sum2 == sum) cout << val << endl;
//        else cout << -1 << endl;

        //cout << val << endl;

        for(lli i = 1; i*i <= val; i++){
            if(i == 1 || i == val) continue;

            if(val%i == 0){
                d1 = i; d2 = val/i;
                if(d1 == d2) v.push_back(d1);
                else {v.push_back(d1); v.push_back(d2);}
            }
        }
        sort(v.begin(), v.end());
        lli sz = v.size();

        if(sz != n) cout << -1 << endl;
        else{
            int flag = 0;
            for(int i = 0; i < n; i++){
                if(v[i] != a[i]) {flag = 1; break;}
            }
            if(!flag) cout << val << endl;
            else cout << -1 << endl;
        }
//
//        if(cnt == n) cout << val << endl;
//        else cout << -1 << endl;
//
//        lli lcm = a[0], gcd, mul;
//
//        for(lli i = 1; i < n; i++){
//            mul = lcm * a[i];
//            gcd = __gcd(lcm, a[i]);
//
//            lcm = mul/gcd;
//        }
//        if(lcm == a[n-1]){
//            if(PRIME[lcm] == 0) cout << (lcm*lcm) << endl;
//            else cout << -1 << endl;
//        }
//        else cout << lcm << endl;
    }

    //}

    return 0;
}


#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;

template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

int PRIME[1000000];

void P()
{
    for(int i = 2; i*i <= 1e6; i++){
        if(PRIME[i] == 0){
            for(int j = 2*i; j <= 1e6; j += i) PRIME[j] = 1;
        }
    }
}

int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    P();

    int t, n;

    cin >> t;

    while(t--){
        cin >> n;

        map<ll, ll> mp;

        ll a[n+5], val, cnt = 0, d1, d2;

        for(int i = 0; i < n; i++) {cin >> a[i]; mp[a[i]] = 1;}

        sort(a, a+n);

        if(n == 1){
            if(PRIME[a[0]] == 0) cout << a[0]*a[0] << endl;
            else cout << -1 << endl;
            continue;
        }
        else val = a[0] * a[n-1];

        for(int i = 1; i*i <= val; i++){
            if(i == 1 || i == val) continue;

            if(val%i == 0){
                d1 = i; d2 = val/i;
                if(mp[d1] == 0 || mp[d2] == 0) {break;}
                else if(d1 != d2) cnt += 2;
                else cnt++;
            }
        }

        if(cnt == n) cout << val << endl;
        else cout << -1 << endl;
    }

    //}

    return 0;
}