#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
#define   int          long long
#define   forn(i,n)    for(int i=0;i<n;i++)
#define   forr(i,a,b)  for(int i=a;i<=b;i++)
#define   mem(ar,x)    memset(ar,x,sizeof ar)
#define   all(x)       x.begin(),x.end()
#define   Lcm(a,b)     (a*(b/__gcd(a,b)))
#define   __p(x,n)     for(int i=0;i<n;i++) { cerr << "\033[94m"<< " " <<x[i]<< "\033[0m"; } cerr<<'\n';
#define   fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   PB           push_back
#define   F            first
#define   S            second
#define   MP           make_pair
#define   vll          __int128_t
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef vector<int>VI;
typedef pair<int,int>PII;
typedef vector<PII>VPII;

const int xx = 1e5;
const int mod = 1e9+7;
const int inf = 1e18;
signed main(){
    int t;
    cin >> t;
    while(t--) {
    int n;
    cin >> n;
    vector<int>v(n);
    vector<int>a,b;
    a.push_back(1);
    for(int i=0;i<n;i++) {
        cin >> v[i];
        a.push_back(v[i]);
    }
    int lc = v[0];
    int gc=0;
    int mx = 0;
    if(n==1 && v[0]==2) {
        cout<<4<<endl;
        continue;
    }
    if(n==1) {
        cout<<-1<<endl;
        continue;
    }
    sort(v.begin() , v.end());
    for(int i=0;i<n;i++) {
        lc = Lcm(lc,v[i]);
        gc = __gcd(gc , v[i]);
        mx = max(mx , v[i]);
    }
    a.push_back(lc);

    for(int i=1;i*i<=lc;i++) {
        if(lc % i == 0) {
            if(i == lc/i){
                b.push_back(i);
            }
            else{
                b.push_back(i);
                b.push_back(lc/i);
            }
        }
    }
    sort(all(a));
    sort(all(b));
    if(a.size() != b.size()){
        cout<<-1<<endl;
        continue;
    }
    for(int i=0;i<a.size();i++){
        if(a[i] != b[i]) {
            cout<<-1<<endl;
            continue;
        }
    }
    cout << lc << endl;

    }

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];
        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1];
       // _deb(ans);
        if(sqrt(ans)*sqrt(ans) == ans){
            int x = v[n/2];
           // _deb(x);
            if(x*x != ans) {
                cout << - 1 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1] != ans){
                ans = -1;
                break;
            }
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];

        if(n==1 && v[0]%2==0) {
            cout << -1 << '\n';
            continue;
        }
        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1] * 1LL;
       // _deb(ans);
        if(sqrt(ans)*sqrt(ans) == ans){
            int x = v[n/2];
           // _deb(x);
            if(x*x != ans) {
                cout << - 1 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1]*1LL != ans){
                ans = -1;
                break;
            }
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
#define int long long
using namespace std;
signed main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];

        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1] * 1LL;
       // _deb(ans);
        if((int)sqrt(ans)*(int)sqrt(ans) == ans){
            int x = v[n/2];
           // _deb(x);
            if(x*x != ans) {
                cout << - 1 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1]*1LL != ans){
                ans = -1;
                break;
            }
        }
        int cnt = 0;
        for(int i=1;i*i<=ans;i++){
            if(ans % i == 0) {
                if(ans/i == i) cnt++;
                else cnt+=2;
            }
        }
      //  _deb(cnt);_deb(ans);
        if(cnt != n+2) {
            cout << -1 << '\n';
            continue;
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];
        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1];
        if(sqrt(ans)*sqrt(ans) == ans){
            int x = v[n/2];
            if(x*x != ans) {
                cout << - 11 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1] != ans){
                ans = -1;
                break;
            }
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];
        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1];
        if(sqrt(ans)*sqrt(ans) == ans){
            int x = v[n/2];
            if(x*x != ans) {
                cout << - 1 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1] != ans){
                ans = -1;
                break;
            }
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];

        if(n==1 && v[0]%2==0 && v[0] > 2) {
            cout << -1 << '\n';
            continue;
        }
        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1] * 1LL;
       // _deb(ans);
        if((int)sqrt(ans)*(int)sqrt(ans) == ans){
            int x = v[n/2];
           // _deb(x);
            if(x*x != ans) {
                cout << - 1 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1]*1LL != ans){
                ans = -1;
                break;
            }
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
#define   int          long long
#define   forn(i,n)    for(int i=0;i<n;i++)
#define   forr(i,a,b)  for(int i=a;i<=b;i++)
#define   mem(ar,x)    memset(ar,x,sizeof ar)
#define   all(x)       x.begin(),x.end()
#define   Lcm(a,b)     (a*(b/__gcd(a,b)))
#define   __p(x,n)     for(int i=0;i<n;i++) { cerr << "\033[94m"<< " " <<x[i]<< "\033[0m"; } cerr<<'\n';
#define   fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   PB           push_back
#define   F            first
#define   S            second
#define   MP           make_pair
#define   vll          __int128_t
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef vector<int>VI;
typedef pair<int,int>PII;
typedef vector<PII>VPII;

const int xx = 1e5;
const int mod = 1e9+7;
const int inf = 1e18;
int divcnt(int n) {
    int cnt = 0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            cnt++;
            if(n/i != i) cnt++;
        }
    }
    return cnt;
}
signed main(){
    int t;
    cin >> t;
    while(t--) {
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int lc = v[0];
    int gc=0;
    int mx = 0;
    if(n==1 && v[0]==2) {
        cout<<4<<endl;
        continue;
    }
    if(n==1) {
        cout<<-1<<endl;
        continue;
    }
    sort(v.begin() , v.end());
    for(int i=0;i<n;i++) {
        lc = Lcm(lc,v[i]);
        gc = __gcd(gc , v[i]);
        mx = max(mx , v[i]);
    }
     int x = divcnt(lc);
     if(x == n+2) {
         cout << lc << endl;
     }
     else{
         cout<<-1<<endl;
     }

    }

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int>v(n);
        for(int i=0;i<n;i++) cin >> v[i];

        if(n==1 && v[0]%2==0 && v[0] > 2) {
            cout << -1 << '\n';
            continue;
        }
        sort(v.begin() , v.end());
        int ans = v[0] * v[n-1] * 1LL;
       // _deb(ans);
        if(sqrt(ans)*sqrt(ans) == ans){
            int x = v[n/2];
           // _deb(x);
            if(x*x != ans) {
                cout << - 1 << '\n';
                continue;
            }
        }
        for(int i=0;i<(n/2);i++) {
            if(v[i]*v[n-i-1]*1LL != ans){
                ans = -1;
                break;
            }
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
#define   int          long long
#define   forn(i,n)    for(int i=0;i<n;i++)
#define   forr(i,a,b)  for(int i=a;i<=b;i++)
#define   mem(ar,x)    memset(ar,x,sizeof ar)
#define   all(x)       x.begin(),x.end()
#define   Lcm(a,b)     (a*(b/__gcd(a,b)))
#define   __p(x,n)     for(int i=0;i<n;i++) { cerr << "\033[94m"<< " " <<x[i]<< "\033[0m"; } cerr<<'\n';
#define   fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   PB           push_back
#define   F            first
#define   S            second
#define   MP           make_pair
#define   vll          __int128_t
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef vector<int>VI;
typedef pair<int,int>PII;
typedef vector<PII>VPII;

const int xx = 1e5;
const int mod = 1e9+7;
const int inf = 1e18;
signed main(){
    int t;
    cin >> t;
    while(t--) {
    int n;
    cin >> n;
    vector<int>v(n);
    vector<int>a,b;
    a.push_back(1);
    for(int i=0;i<n;i++) {
        cin >> v[i];
        a.push_back(v[i]);
    }
    int lc = v[0];
    int gc=0;
    int mx = 0;
    if(n==1 && v[0]==2) {
        cout<<4<<endl;
        continue;
    }

    sort(v.begin() , v.end());
    for(int i=0;i<n;i++) {
        lc = Lcm(lc,v[i]);
        gc = __gcd(gc , v[i]);
        mx = max(mx , v[i]);
    }
    if(lc == mx) lc = mx+mx;
    a.push_back(lc);
   // _deb(lc);_deb(mx);

    for(int i=1;i*i<=lc;i++) {
        if(lc % i == 0) {
            if(i == lc/i){
                b.push_back(i);
            }
            else{
                b.push_back(i);
                b.push_back(lc/i);
            }
        }
    }
    sort(all(a));
    sort(all(b));
    if(a.size() != b.size()){
        cout<<-1<<endl;
        continue;
    }
    for(int i=0;i<a.size();i++){
        if(a[i] != b[i]) {
            cout<<-1<<endl;
            continue;
        }
    }
    cout << lc << endl;

    }

}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
#define   int          long long
#define   forn(i,n)    for(int i=0;i<n;i++)
#define   forr(i,a,b)  for(int i=a;i<=b;i++)
#define   mem(ar,x)    memset(ar,x,sizeof ar)
#define   all(x)       x.begin(),x.end()
#define   Lcm(a,b)     (a*(b/__gcd(a,b)))
#define   __p(x,n)     for(int i=0;i<n;i++) { cerr << "\033[94m"<< " " <<x[i]<< "\033[0m"; } cerr<<'\n';
#define   fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   PB           push_back
#define   F            first
#define   S            second
#define   MP           make_pair
#define   vll          __int128_t
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef vector<int>VI;
typedef pair<int,int>PII;
typedef vector<PII>VPII;

const int xx = 1e5;
const int mod = 1e9+7;
const int inf = 1e18;
int divcnt(int n) {
    int cnt = 0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            cnt++;
            if(n/i != i) cnt++;
        }
    }
    return cnt;
}
signed main(){
    int t;
    cin >> t;
    while(t--) {
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int lc = v[0];
    int gc=0;
    int mx = 0;
    if(n==1 && v[0]==2) {
        cout<<4<<endl;
        continue;
    }
    if(n==1) {
        cout<<-1<<endl;
        continue;
    }
    sort(v.begin() , v.end());
    for(int i=0;i<n;i++) {
        lc = Lcm(lc,v[i]);
        gc = __gcd(gc , v[i]);
        mx = max(mx , v[i]);
    }
     int x = divcnt(lc);
     if(x == n+2 && lc > mx) {
         cout << lc << endl;
     }
     else{
         cout<<-1<<endl;
     }

    }

}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*2<<endl;
			continue;
		}
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		int cnt=0;
		ll ss=sqrt(x);
		for(ll i=2;i<ss;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			}
		}
		if(ss*ss==x)
		e[++cnt]=ss;
		sort(e+1,e+1+cnt);
		for(int i=1;i<=n;i++)
		{
			//cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			//	cout<<e[cnt]<<"--"<<e[cnt-1]<<endl;
			}
		}
		if(i*i==x)
		e[++cnt]=i;
		sort(e+1,e+1+cnt);
		//cout<<cnt<<endl;
		for(int i=1;i<=n;i++)
		{
		//	cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
ll gcd(ll a,ll b)
{
	if(b==0)
	return a;
	return gcd(b,a%b);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	ll x=d[1];
    	bool flag=true;
    	for(int i=2;i<=n;i++)
    	{
    		ll w=gcd(x,d[i-1]);
    		x=x/w*d[i-1];
    		if(x>1e12)
    		{
    			flag=false;
    			break;
			}
		}
		sort(d+1,d+1+n);
		int cnt=0;
		for(int i=2;i<x;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
			}
		}
		for(int i=1;i<=n;i++)
		if(e[i]!=d[i])
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
int vis[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*d[1]<endl;
			continue;
		}
		memset(vis,0,sizeof(0));
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		for(int i=1;i<=n;i++)
		{
			vis[d[i]]=1;
		}
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				if(vis[i]!=1)
				flag=false;
				cnt++;
				if(vis[x/i]!=1)
				flag=false;
				cnt++;
			}
		}
		if(i*i==x)
		{
			if(vis[i]!=1)
				flag=false;
				cnt++;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
ll gcd(ll a,ll b)
{
	if(b==0)
	return a;
	return gcd(b,a%b);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	ll x=d[1];
    	bool flag=true;
    	for(int i=2;i<=n;i++)
    	{
    		ll w=gcd(x,d[i-1]);
    		x=x/w*d[i-1];
    		if(x>1e12)
    		{
    			flag=false;
    			break;
			}
		}
		sort(d+1,d+1+n);
		int cnt=0;
		for(int i=2;i<x;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
			}
		}
		for(int i=1;i<=n;i++)
		if(e[i]!=d[i])
		flag=false;
		if(n==1)
		{
			cout<<x*2<<endl;
			continue;
		}
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
ll gcd(ll a,ll b)
{
	if(b==0)
	return a;
	return gcd(b,a%b);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	ll x=d[1];
    	bool flag=true;
    	ll ma=0,mi=10000000;
    	for(int i=1;i<=n;i++)
    	{
			ma=max(d[i],ma);
			mi=min(mi,d[i]);
			/*
    		ll w=gcd(x,d[i-1]);
    		x=x/w*d[i-1];
    		if(x>1e12)
    		{
    			flag=false;
    			break;
			}*/
		}
		x=ma*mi;
		sort(d+1,d+1+n);
		int cnt=0;
		int ss=sqrt(x);
		for(int i=2;i<=ss;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			}
		}
		sort(e+1,e+1+n);
		for(int i=1;i<=n;i++)
		{
			//cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n==1)
		{
			cout<<d[1]*2<<endl;
			continue;
		}
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*d[1]<<endl;
			continue;
		}
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			//	cout<<e[cnt]<<"--"<<e[cnt-1]<<endl;
			}
		}
		if(i*i==x)
		e[++cnt]=i;
		sort(e+1,e+1+cnt);
		//cout<<cnt<<endl;
		for(int i=1;i<=n;i++)
		{
		//	cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*2<<endl;
			continue;
		}
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		int cnt=0;
		int ss=sqrt(x);
		for(ll i=2;i<ss;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			}
		}
		if(i*i=ss)
		e[++cnt]=i;
		sort(e+1,e+1+cnt);
		for(int i=1;i<=n;i++)
		{
			//cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
int vis[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*d[1]<<endl;
			continue;
		}
		memset(vis,0,sizeof(0));
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		for(int i=1;i<=n;i++)
		{
			vis[d[i]]=1;
		}
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				if(vis[i]!=1)
				flag=false;
				cnt++;
				if(vis[x/i]!=1)
				flag=false;
				cnt++;
			}
		}
		if(i*i==x)
		{
			if(vis[i]!=1)
				flag=false;
				cnt++;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
int vis[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
		memset(vis,0,sizeof(0));
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		for(int i=1;i<=n;i++)
		{
			vis[d[i]]=1;
		}
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				if(vis[i]!=1)
				flag=false;
				cnt++;
				if(vis[x/i]!=1)
				flag=false;
				cnt++;
			}
		}
		if(i*i==x)
		{
			if(vis[i]!=1)
				flag=false;
				cnt++;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
ll gcd(ll a,ll b)
{
	if(b==0)
	return a;
	return gcd(b,a%b);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	ll x=d[1];
    	bool flag=true;
    	for(int i=2;i<=n;i++)
    	{
    		ll w=gcd(x,d[i-1]);
    		x=x/w*d[i-1];
    		if(x>1e12)
    		{
    			flag=false;
    			break;
			}
		}
		sort(d+1,d+1+n);
		int cnt=0;
		int ss=sqrt(x);
		for(int i=2;i<=ss;i++)
		{

			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			}
		}
		sort(e+1,e+1+n);
		for(int i=1;i<=n;i++)
		//cout<<e[i]<<"   "<<d[i]<<endl;
		if(e[i]!=d[i])
		flag=false;
		if(n==1)
		{
			cout<<x*2<<endl;
			continue;
		}
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
int vis[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*2<<endl;
			continue;
		}
		memset(vis,0,sizeof(0));
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		for(int i=1;i<=n;i++)
		{
			vis[d[i]]=1;
		}
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				if(vis[i]!=1)
				flag=false;
				cnt++;
				if(vis[x/i]!=1)
				flag=false;
				cnt++;
			}
		}
		if(i*i==x)
		{
			if(vis[i]!=1)
				flag=false;
				cnt++;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	ll x=d[1];
    	bool flag=true;
    	ll ma=0,mi=10000000;
    	for(int i=1;i<=n;i++)
    	{
			ma=max(d[i],ma);
			mi=min(mi,d[i]);
			/*
    		ll w=gcd(x,d[i-1]);
    		x=x/w*d[i-1];
    		if(x>1e12)
    		{
    			flag=false;
    			break;
			}*/
		}
		x=ma*mi;
		sort(d+1,d+1+n);
		int cnt=0;
		int ss=sqrt(x);
		for(int i=2;i<=ss;i++)
		{
			if(x%i==0)
			{
				if(i*i==x)
				e[++cnt]=i;
				else
				{
					e[++cnt]=i;
					e[++cnt]=x/i;
				}
			}
		}
		sort(e+1,e+1+n);
		for(int i=1;i<=n;i++)
		{
			//cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n!=cnt)
		flag=false;
		if(n==1)
		{
			cout<<d[1]*2<<endl;
			continue;
		}
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
ll e[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
    	if(n==1)
		{
			cout<<d[1]*2<<endl;
			continue;
		}
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				e[++cnt]=i;
				e[++cnt]=x/i;
			//	cout<<e[cnt]<<"--"<<e[cnt-1]<<endl;
			}
		}
		if(i*i==x)
		e[++cnt]=i;
		sort(e+1,e+1+cnt);
		//cout<<cnt<<endl;
		for(int i=1;i<=n;i++)
		{
		//	cout<<e[i]<<"   "<<d[i]<<endl;
			if(e[i]!=d[i])
				flag=false;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
const int M = 2000000+100;
using namespace std;
typedef long long ll;
ll d[M];
int vis[M];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    while(q--)
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	cin>>d[i];
    	bool flag=true;
		memset(vis,0,sizeof(vis));
		sort(d+1,d+1+n);
		ll x=d[1]*d[n];
		for(int i=1;i<=n;i++)
		{
			vis[d[i]]=1;
		}
		int cnt=0;
		ll i;
		for( i=2;i*i<x;i++)
		{
			if(x%i==0)
			{
				if(vis[i]!=1)
				flag=false;
				cnt++;
				if(vis[x/i]!=1)
				flag=false;
				cnt++;
			}
		}
		if(i*i==x)
		{
			if(vis[i]!=1)
				flag=false;
				cnt++;
		}
		if(n!=cnt)
		flag=false;
		if(flag)
		cout<<x<<endl;
		else
		cout<<-1<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
ll sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[10001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=1;
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
       for(ll i=2;i<10001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    //cout<<i<<" ";
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }
       if(n==1)
       {
          if(!P[a[0]])cout<<a[0]*a[0]<<ln;
          else cout<<"-1\n";
       }
       else
       if(f)cout<<u<<ln;
       else cout<<"-1\n";
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
ll sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=pow(i,b[i]+1);}
      if(c==1)cout<<y<<ln;
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=pow(i,b[i]+1);}
      if(c==1)cout<<y<<ln;
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
//#define F(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
//ll sieve(){F(i,2,on) if(!P[i]) for(ll j=i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    while(t--)
    {
      cin>>n;
      ll a[n];
      f(i,n)    cin>>a[i];
      x=a[0];
      m=a[0];
      f(i,n)
      {
          u=hcf(x,a[i]);
          x=(x*a[i])/u;
          m=max(m,a[i]);
      }
      sort(a,a+n);
      if(m==x)x=2*a[0];
      cout<<x<<ln;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              u=x;
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
              if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }
             if(!P[u/j]&&(u/j>1))
             {

                ll c=0;

                  while(x%(u/j)==0)
                  {

                      x=x/(u/j);
                      c++;
                  }
                  b[u/j]=max(b[u/j],c);

             }
          }
          if(!P[x])
              {
                  b[x]=max(w,b[x]);
              }

      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
           //cout<<y;
         if(h==n)cout<<(ll)pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
//#define F(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
//ll sieve(){F(i,2,on) if(!P[i]) for(ll j=i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    while(t--)
    {
      cin>>n;
      ll a[n];
      f(i,n)    cin>>a[i];
      x=a[0];
      m=a[0];
      f(i,n)
      {
          u=hcf(x,a[i]);
          x=(x*a[i])/u;
          m=max(m,a[i]);
      }
      if(m==x)x=2*x;
      cout<<x<<ln;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              u=x;
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
              if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }
             if(!P[u/j]&&(u/j>1))
             {

                ll c=0;

                  while(x%(u/j)==0)
                  {

                      x=x/(u/j);
                      c++;
                  }
                  b[u/j]=max(b[u/j],c);

             }
          }
          if(!P[x])
              {
                  b[x]=max(w,b[x]);
              }

      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h,g=1;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
           //cout<<y;
         if(h==n)cout<<(ll)pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
                g*=b[i]+1;
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }
        f(i,n)
           {
               if(u==a[i])f=0;
           }
           if(g!=n+2)f=0;
       if(f)
       {
        cout<<u<<ln;
       }
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              u=x;
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
              if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }
             if(!P[u/j]&&(u/j!=1))
             {
                 ll c=0;
                  while(x%(u/j)==0)
                  {
                      x/=u/j;
                      c++;
                  }
                  b[u/j]=max(b[u/j],c);
             }
          }
          if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }

      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
         // cout<<b[3];
         if(h==n)cout<<(ll)pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
//#define F(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
//ll sieve(){F(i,2,on) if(!P[i]) for(ll j=i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    while(t--)
    {
      cin>>n;
      ll a[n];
      f(i,n)    cin>>a[i];
      x=a[0];
      f(i,n)
      {
          u=hcf(x,a[i]);
          x=(x*a[i])/u;
      }
      if(n==1)x=x*x;
      cout<<x<<ln;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              u=x;
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
              if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }
            /* if(!P[u/j]&&(u/j!=1))
             {
                 ll c=0;

                 // while(x%(u/j)==0)
                  {
                     // x=x/(u/j);
                      c++;
                  }
                 // b[u/j]=max(b[u/j],c);
             }*/
          }
          if(!P[x])
              {
                  b[x]=max(w,b[x]);
              }

      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
           //cout<<y;
         if(h==n)cout<<(ll)pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
ll sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=1;
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
       for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    //cout<<i<<" ";
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }
       if(n==1)
       {
          if(!P[a[0]])cout<<a[0]*a[0]<<ln;
          else cout<<"-1\n";
       }
       else
       if(f)cout<<u<<ln;
       else cout<<"-1\n";
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=1;
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
       for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    //cout<<i<<" ";
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }
       if(n==1)
       {
          if(!P[a[0]])cout<<a[0]*a[0]<<ln;
          else cout<<"-1\n";
       }
       else
       if(f)cout<<u<<ln;
       else cout<<"-1\n";
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              u=x;
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
              if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }
             if(!P[u/j]&&(u/j>1))
             {

                ll c=0;

                  while(x%(u/j)==0)
                  {

                      x=x/(u/j);
                      c++;
                  }
                  b[u/j]=max(b[u/j],c);

             }
          }
          if(!P[x])
              {
                  b[x]=max(w,b[x]);
              }

      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
           //cout<<y;
         if(h==n)cout<<(ll)pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }
        f(i,n)
           {
               if(u==a[i])f=0;
           }
       if(f)
       {
        cout<<u<<ln;
       }
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
         if(b[i]==n)cout<<pow(y,b[i]+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
         if(h==n)cout<<pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              u=x;
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
              if(!P[x]&&x!=1)
              {
                  b[x]=max(w,b[x]);
                  break;
              }
             if(!P[u/j]&&(u/j>1))
             {

                ll c=0;

                  while(x%(u/j)==0)
                  {

                      x=x/(u/j);
                      c++;
                  }
                  b[u/j]=max(b[u/j],c);

             }
          }
          if(!P[x])
              {
                  b[x]=max(w,b[x]);
              }

      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h,g=1;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}

        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
                g*=b[i]+1;
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

           if(g!=n+2)f=0;
       if(f)
       {
        cout<<u<<ln;
       }
       else cout<<"-1\n";

    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
ll sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[10001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y;
       for(ll i=2;i<10001;i++)
       if(b[i]){c++;y=pow(i,b[i]+1);}
      if(c==1)cout<<y<<ln;
      else
      {
        for(ll i=2;i<10001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
ll sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=1;
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=pow(i,b[i]+1);}
      if(c==1)cout<<y<<ln;
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y,h;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=i;h=b[i];}
      if(c==1)
      {
         if(h==n)cout<<(ll)pow(y,h+1)<<ln;
         else cout<<"-1\n";
      }
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
               if(u<0)f=0;
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
//#define F(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
//ll sieve(){F(i,2,on) if(!P[i]) for(ll j=i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    while(t--)
    {
      cin>>n;
      ll a[n];
      f(i,n)    cin>>a[i];
      x=a[0];
      m=a[0];
      f(i,n)
      {
          u=hcf(x,a[i]);
          x=(x*a[i])/u;
          m=max(m,a[i]);
      }
      sort(a,a+n);
      if(m==x)x=x*a[0];
      cout<<x<<ln;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sb substr
#define ll long long int
#define REP(i,x,b) for(ll i=x;i<b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define rp(x,n) for(ll i=x;i<n;i++)
#define HI for(int i=0;i<n;i++)cin>>a[i]
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define fast     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define vi vector<int>
#define on (10000005)
const int M=5e6+5;//5e8+5;
const ll mod=1e9+7;
const ll inf = 9e18;
const double pi = 3.14159265358979323846;
ll t,n,m,x,sum,k,p,u=0;
string s,z,ans="";
ll P[10000005]={0};
void sieve(){REP(i,2,on) if(!P[i]) for(ll j=i*i;j<on;j+=i) P[j]=i;}

ll raised(ll x, ll v) {
	if (v == 0)
		return 1 % mod;

	if (v % 2 == 1)
		return (x * raised(x, v - 1)) % mod;

	ll r = raised(x, v / 2);

	return (r * r) % mod;
}
bool prime(ll n)
{
    if(n==1)return 1;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)return 0;
    return 1;
}
ll hcf(ll a,ll b)
{
    if(a%b==0)return b;
    return hcf(b,a%b);
}

/*int C[1000001]={0};
void pascal(int n, int r, int p)
{

	C[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j =i; j > 0; j--)
			C[j] = (C[j] + C[j - 1]) % p;
	}
	//return C[r];
}*/

//puts(u>5?"YES":"NO");
/*
void DFS(bool vis[],vector<int>adj[],int a)
{
    vis[a]=1;
    for(int i=0;i<adj[a].size();i++)
    {
        if(!vis[adj[a][i]])
        {
            DFS(vis,adj,adj[a][i]);
        }
    }
}*/
struct smp{
bool operator() (const pair<ll,ll>&a,const pair<ll,ll>&b)const
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}
};
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.F==b.F)return (a.S<b.S);
    return (a.F>b.F);
}

int main() {
    fast;
    cin>>t;
    ll w=1;
    sieve();
    while(t--)
    {
      cin>>n;
      ll a[n],b[1000001]={0};
      f(i,n)
      {
          cin>>a[i];
          x=a[i];
          if(!P[x])b[x]=max(w,b[x]);
          else
          for(int j=2;j<=sqrt(a[i]);j++)
          {
              if(x%j==0&&!P[j])
              {
                  ll c=0;
                  while(x%j==0)
                  {
                      x/=j;
                      c++;
                  }
                  b[j]=max(b[j],c);
              }
          }
      }
      bool f=1;
      u=1;
        ll c=0;
         ll y;
       for(ll i=2;i<1000001;i++)
       if(b[i]){c++;y=pow(i,b[i]+1);}
      if(c==1)cout<<y<<ln;
      else
      {
        for(ll i=2;i<1000001;i++)
       {
           if(b[i])
           {
               if((n+2)%(b[i]+1))
                {
                    f=0;break;
                }
               u*=pow(i,b[i]);
           }
       }

       if(f)cout<<u<<ln;
       else cout<<"-1\n";
      }
    }

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; ++i){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            int k=0;
            for(int i=2; i*i<=p; ++i){
                if(p%i==0){
                    k+=2;
                }
            }
            if(sqrt(p)*sqrt(p)==p)
                k--;

            if(k==n)
                cout<<p<<endl;
            else cout<<-1<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

bool was[(int)(2e5+100)];
ll a[500];
ll b[500];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];
        int t=0;
        bool ok=true;
        for(int i=2; i*i<=p; i++){
            if(p%i==0){
                if(i*i!=p){
                    t++;
                    b[t]=i;
                }
                t++;
                b[t]=p/i;
            }
        }

        sort(b+1,b+t+1);
        if(t!=n){
            cout<<-1;
            continue;
        }
        for(int i=1; i<=n; i++){
            if(a[i]!=b[i]){
                cout<<-1;
                ok=false;
                break;
            }
        }
        if(ok)
            cout<<a[1]*a[n]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

bool was[(int)(2e5+100)];
ll a[500];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];
        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n-i+1]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok)
            cout<<a[1]*a[n]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            ll k=0;
            for(int i=2; i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                    if(i*i==p)
                        k--;
                }
            }

            if(k!=n)
                cout<<-1<<endl;
            else cout<<p<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            int k=0;
            for(ll i=2; i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                    if(i*i==p)
                        k--;
                }
            }
            if(k==n)
                cout<<p<<endl;
            else cout<<-1<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            int k=0;
            for(int i=2; i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                }
            }
            if(sqrt(p)*sqrt(p)==p)
                k--;
            cout<<p<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

bool was[(int)(2e5+100)];
ll a[500];
ll b[500];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];
        int t=0;
        bool ok=true;
        for(int i=2; i*i<=p; i++){
            if(p%i==0){
                if(i*i!=p){
                    t++;
                    b[t]=i;
                }
                t++;
                b[t]=p/i;
            }
        }

        sort(b+1,b+t+1);
        if(t!=n){
            cout<<-1<<endl;
            continue;
        }
        for(int i=1; i<=n; i++){
            if(a[i]!=b[i]){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok)
            cout<<a[1]*a[n]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            int k=0;
            for(int i=2; i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                }
            }
            if(sqrt(p)*sqrt(p)==p)
                k--;
            if(k==n)
                cout<<p<<endl;
            else cout<<-1<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

bool was[(int)(2e5+100)];
ll a[500];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        cout<<a[1]*a[n]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            ll k=0;
            for(int i=2; (ll)i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                    if(i*i==p)
                        k--;
                }
            }

            if(k!=n)
                cout<<-1<<endl;
            else cout<<p<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

bool was[(int)(2e5+100)];
ll a[500];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        int p=a[1]*a[n];
        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n-i+1]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok)
            cout<<a[1]*a[n]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

bool was[(int)(2e5+100)];
ll a[500];

int main(){
    int t;
    cin>>t;
    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        int p=a[1]*a[n];
        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n-i+1]!=p){
                cout<<-1;
                ok=false;
                break;
            }
        }
        if(ok)
            cout<<a[1]*a[n]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            ll k=0;
            for(int i=2; i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                }
            }

            if(sqrt(p)*sqrt(p)==p)
                k--;

            if(k==n)
                cout<<p<<endl;
            else cout<<-1<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

ll a[500];

int main(){
    int t;
    cin>>t;

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];

        bool ok=true;
        for(int i=1; i<=(n+1)/2; i++){
            if(a[i]*a[n+1-i]!=p){
                cout<<-1<<endl;
                ok=false;
                break;
            }
        }
        if(ok){
            ll k=0;
            for(int i=2; i*i<=p; i++){
                if(p%i==0){
                    k+=2;
                    if(i*i==p)
                        k--;
                }
            }

            if(k==n)
                cout<<p<<endl;
            else cout<<-1<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define pii pair<int,int>

int d[(int)(1e6+110)];
ll a[500];

int main(){
    int t;
    cin>>t;

    for(int i=1; i<=1e6; i++){
        for(int j=i; j<=1e6; j+=i){
            d[j]++;
        }
    }

    for(int k=1; k<=t; k++){
        int n;
        cin>>n;
        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        ll p=a[1]*a[n];
        if(d[p]-2!=n){
            cout<<-1<<endl;
        }else{
            bool ok=true;
            for(int i=1; i<=(n+1)/2; i++){
                if(a[i]*a[n+1-i]!=p){
                    cout<<-1<<endl;
                    ok=false;
                    break;
                }
            }
            if(ok){
                cout<<p<<endl;
            }
        }
    }
    return 0;
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 990000 && n != 1)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}