A prime number is number x which has only divisors as 1 and x itself.
Harsh is playing a game with his friends, where his friends give him a few numbers claiming that they are divisors of some number x but divisor 1 and the number x itself are not being given as divisors.
You need to help harsh find which number's divisors are given here.
His friends can also give him wrong set of divisors as a trick question for which no number exists.
Simply, We are given the divisors of a number x ( divisors except 1 and x itself ) , you have to print the number if only it is possible.
You have to answer t queries.
(USE LONG LONG TO PREVENT OVERFLOW)

-----Input:-----
- First line is T queires.
- Next are T queries.
- First line is N ( No of divisors except 1 and the number itself )
- Next line has N integers or basically the divisors.

-----Output:-----
Print the minimum possible x which has such divisors and print -1 if not possible.

-----Constraints-----
- 1<= T <= 30
- 1<= N <= 350
- 2<= Di <=10^6

-----Sample Input:-----
3
2
2 3
2
4 2
3
12 3 2

-----Sample Output:-----
6
8
-1

-----EXPLANATION:-----
Query 1 : Divisors of 6 are ( 1,2,3,6) Therefore, Divisors except 1 and the number 6 itself are ( 2 , 3). Thus, ans = 6.
Query 2 : Divisors of 8 are ( 1,2,4,8) Therefore, Divisors except 1 and the number 8 itself are ( 2 , 4). Thus, ans = 8.
Query 3 : There is no such number x with only ( 1,2,3,12,x ) as the divisors.

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
from math import ceil, sqrt, floor
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = a[0] * a[n - 1]
	div = []
	for i in range(2, floor(sqrt(x)) + 1):
		if x % i == 0:
			div.append(i)
			y = x // i
			if i != y:
				div.append(y)
	div.sort()
	if a == div:
		print(x)
	else:
		print(-1)


ddd = 0

def prime(n):
	if n < 2:
		return []
	else:
		n += 1
		save = [True] * (n // 2)
		for i in range(3, int(n ** 0.5) + 1, 2):
			if save[i // 2]:
				k = i * i
				save[k // 2::i] = [False] * ((n - k - 1) // (2 * i) + 1)
	return [2] + [2 * i + 1 for i in range(1, n // 2) if save[i]]
pp = prime(1000000)

def decom(x):
	nns = 0
	arrr = 0
	answer = 1
	while x != 1:
		nonlocal ddd
		ddd += 1
		while x % pp[nns] == 0:
			x = x / pp[nns]
			arrr += 1
		if arrr != 0:
			answer = answer * (arrr + 1)
			arrr = 0
		nns += 1
	return answer - 2
rr = int(input())
p = 0
for i in range(rr):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	ss = arr[0] * arr[n - 1]
	f = 0
	for i in range(n):
		ddd += 1
		if arr[i] * arr[n - 1 - i] != ss:
			f = 1
			break
	if decom(ss) != n:
		f = 1
	if f == 1:
		print(-1)
	else:
		print(ss)


import math

def isp(n):
	i = 2
	j = math.sqrt(n)
	while i <= j:
		if n % i == 0:
			break
		i += 1
	return i > j
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	lst = [0] * 1000001
	ans = 1
	k = 0
	for x in arr:
		if isp(x):
			if lst[x] == 0:
				lst[x] = 1
				ans *= x
			else:
				k += 1
				break
		else:
			i = 2
			j = math.sqrt(x)
			while i <= j:
				if x % i == 0:
					if lst[i] == 0 or lst[x // i] == 0:
						break
				i += 1
			if i <= j:
				k += 1
				break
			elif lst[x] == 0:
				lst[x] = 1
				ans *= x // math.gcd(ans, x)
			else:
				k += 1
				break
	if k:
		print(-1)
	elif ans == arr[n - 1]:
		p = ans
		while p % arr[0] == 0:
			p //= arr[0]
		if p == 1:
			ans *= arr[0]
			print(ans)
		else:
			print(-1)
	else:
		print(ans)
	t -= 1


import math

def factorialToNum(N, n):
	N.sort()
	t = N[0] * N[n - 1]
	L = []
	i = 2
	while i * i <= t:
		if t % i == 0:
			L.append(i)
			if t // i != i:
				L.append(t // i)
		i += 1
	L.sort()
	if len(L) != n:
		return -1
	else:
		j = 0
		for it in range(n):
			if N[j] != L[it]:
				return -1
			else:
				j += 1
	return t
t = int(input())
for _ in range(t):
	n = int(input())
	N = list(map(int, input().strip().split(' ')))
	print(factorialToNum(N, n))


import math
for _ in range(int(input())):
	input()
	l = list(map(int, input().split(' ')))
	l.sort()
	i = 0
	j = len(l) - 1
	n = -1
	f = True
	while i <= j:
		if i == 0:
			n = l[i] * l[j]
		elif l[i] * l[j] != n:
			f = False
			break
		i += 1
		j -= 1
	j = len(l)
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				j -= 1
			else:
				j -= 2
	if f and j == 0:
		print(n)
	else:
		print(-1)


import math

def findX(list, int):
	list.sort()
	x = list[0] * list[int - 1]
	vec = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			vec.append(i)
			if x // i != i:
				vec.append(x // i)
		i += 1
	vec.sort()
	if len(vec) != int:
		return -1
	else:
		j = 0
		for it in range(int):
			if list[j] != vec[it]:
				return -1
			else:
				j += 1
	return x
try:
	m = int(input())
	for i in range(m):
		n = int(input())
		x = list(map(int, input().split()))
		print(findX(x, n))
except EOFError as e:
	print(e)


def fun(l, z):
	l.sort()
	x = l[0] * l[z - 1]
	temp = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			temp.append(i)
			if x // i != i:
				temp.append(x // i)
		i += 1
	temp.sort()
	if len(temp) != z:
		return -1
	else:
		j = 0
		for k in range(z):
			if temp[j] != temp[k]:
				return -1
			else:
				j += 1
	return x
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	print(fun(arr, n))


def solve():
	x = a[0] * a[-1]
	vec = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			vec.append(i)
			if x // i != i:
				vec.append(x // i)
		i += 1
	vec.sort()
	if len(vec) != n:
		return -1
	else:
		j = 0
		for it in range(n):
			if a[j] != vec[it]:
				return -1
			else:
				j += 1
	return x
for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	print(solve())


import math

def findX(list, int):
	list.sort()
	x = list[0] * list[int - 1]
	vec = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			vec.append(i)
			if x // i != i:
				vec.append(x // i)
		i += 1
	vec.sort()
	if len(vec) != int:
		return -1
	else:
		j = 0
		for it in range(int):
			if a[j] != vec[it]:
				return -1
			else:
				j += 1
	return x
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(findX(a, n))