We guessed some integer number $x$. You are given a list of almost all its divisors. Almost all means that there are all divisors except $1$ and $x$ in the list.

Your task is to find the minimum possible integer $x$ that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.

You have to answer $t$ independent queries.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 25$) — the number of queries. Then $t$ queries follow.

The first line of the query contains one integer $n$ ($1 \le n \le 300$) — the number of divisors in the list.

The second line of the query contains $n$ integers $d_1, d_2, \dots, d_n$ ($2 \le d_i \le 10^6$), where $d_i$ is the $i$-th divisor of the guessed number. It is guaranteed that all values $d_i$ are distinct.


-----Output-----

For each query print the answer to it.

If the input data in the query is contradictory and it is impossible to find such number $x$ that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible $x$.


-----Example-----
Input
2
8
8 2 12 6 4 24 16 3
1
2

Output
48
4

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Number theory

Mathematics


Solutions:
Testcases = int(input())
import math

def lcm(x, y):
	return x * y // math.gcd(x, y)
for test in range(Testcases):
	n = int(input())
	A = set(map(int, input().split()))
	ANS = 1
	fl = 1
	for a in A:
		ANS = lcm(a, ANS)
		if ANS > 10 ** 12:
			print(-1)
			fl = 0
			break
	if fl == 0:
		continue
	if ANS in A:
		ANS *= min(A)
	x = ANS
	L = int(math.sqrt(x))
	FACT = dict()
	for i in range(2, L + 2):
		while x % i == 0:
			FACT[i] = FACT.get(i, 0) + 1
			x = x // i
	if x != 1:
		FACT[x] = FACT.get(x, 0) + 1
	PRIMESCORE = 1
	for f in FACT:
		PRIMESCORE *= FACT[f] + 1
	if n + 2 == PRIMESCORE:
		print(ANS)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase

def solve():
	n = int(input())
	a = set(list(map(int, input().split())))
	(i, g, z) = (2, min(a) * max(a), 0)
	while i * i <= g:
		if not g % i:
			if i not in a or g // i not in a:
				return -1
			z += 2
		i += 1
	z -= (i - 1) * (i - 1) == g
	return g if z == n else -1

def main():
	for _ in range(int(input())):
		print(solve())
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(v, s, d) = (min(a) * max(a), set(), 2)
	while d * d <= v:
		if not v % d:
			s.add(d)
			s.add(v / d)
		d += 1
	print(v if s == set(a) else -1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import sqrt

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		arr.sort()

		def ck(num):
			ret = 0
			for i in range(2, int(sqrt(num)) + 1):
				if num % i == 0:
					ret += 1
			return ret
		res = arr[0] * arr[-1]
		if n // 2 + (1 if n % 2 == 1 else 0) != ck(res):
			print(-1)
		else:
			for i in range(1, n // 2 + 1):
				if arr[i] * arr[n - i - 1] != res:
					print(-1)
					break
			else:
				print(res)
main()


I = input
for i in ' ' * int(I()):
	I()
	a = {*map(int, I().split())}
	s = min(a) * max(a)
	d = set()
	i = 2
	while i * i <= s:
		if s % i == 0:
			d |= {i, s // i}
		i += 1
	if a != d:
		s = -1
	print(s)


import math

def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def solve(divs):
	ss = set(divs)
	ans = 1
	for div in divs:
		for i in range(2, int(math.sqrt(div)) + 1):
			if div % i == 0:
				if i not in ss or div // i not in ss:
					return -1
		g = gcd(ans, div)
		ans = ans // g * div
	if ans in ss:
		ans *= sorted(divs)[0]
	if ans > 1 << 64:
		return -1
	for div in divs:
		if ans // div not in ss:
			return -1
	return ans
T = int(input())
for i in range(T):
	N = int(input())
	D = list(map(int, input().strip().split()))
	print(solve(D))


def factors(n):
	from functools import reduce
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	num = max(arr) * min(arr)
	s1 = set(arr)
	s1.add(1)
	s1.add(num)
	s2 = factors(num)
	if s1 == s2:
		print(num)
	else:
		print(-1)


def fact(n):
	l = set()
	x = 2
	while x * x <= n:
		if n % x == 0:
			l.add(x)
			l.add(n // x)
		x += 1
	return l
for _ in range(int(input())):
	n = int(input())
	l = set(map(int, input().split()))
	x = min(l) * max(l)
	m = fact(x)
	if m != l:
		print(-1)
	else:
		print(x)


T = int(input())

def main():
	n = int(input())
	d = [int(e) for e in input().split()]
	d.sort()
	(ans, i, j) = (d[0] * d[-1], 1, n - 2)
	while i <= j:
		if ans != d[i] * d[j]:
			print(-1)
			return
		(i, j) = (i + 1, j - 1)
	(i, x) = (2, ans)
	b = []
	while i * i <= x:
		if x % i == 0:
			b.append(i)
			if x // i != i:
				b.append(x // i)
		i += 1
	b.sort()
	if len(b) != n:
		print(-1)
		return
	for i in range(n):
		if d[i] != b[i]:
			print(-1)
			return
	print(ans)
for cas in range(T):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = set(map(int, input().split()))
	small = min(arr)
	large = max(arr)
	number = small * large
	factors = set()
	for num in range(2, int(number ** 0.5) + 1):
		if number % num == 0:
			factors.add(num)
			factors.add(number // num)
	if arr == factors:
		print(number)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	limit = 10 ** 6
	minA = limit + 1
	maxA = 0
	mark = {}
	for v in a:
		if v < minA:
			minA = v
		if v > maxA:
			maxA = v
		mark[str(v)] = 1
	ans = minA * maxA
	(l, r) = (2, ans)
	c = l
	while c < r:
		if ans % c == 0:
			t1 = str(c)
			t2 = str(ans // c)
			if t1 not in mark or t2 not in mark:
				ans = -1
				break
			else:
				del mark[t1]
				if t2 in mark:
					del mark[t2]
			r = ans // c
		c += 1
	if ans != -1:
		for (k, v) in mark.items():
			if ans % int(k) != 0:
				ans = -1
				break
	print(ans)


for _ in range(int(input())):
	input()
	s = set(map(int, input().split()))
	ans = min(s) * max(s)
	for i in range(2, int(ans ** 0.5) + 1):
		if ans % i == 0 and (i not in s or ans // i not in s):
			print(-1)
			break
	else:
		if any((ans % i for i in s)):
			print(-1)
		else:
			print(ans)


for j in range(int(input())):
	q = int(input())
	s = list(map(int, input().split()))
	m = min(s) * max(s)
	for i in range(2, int(m ** 0.5) + 1):
		if m % i == 0 and (i not in s or m // i not in s):
			print(-1)
			break
	else:
		for i in s:
			if m % i != 0:
				print(-1)
				break
		else:
			print(m)


t = int(input())
for _ in range(t):
	n = int(input())
	divisors = sorted(map(int, input().split()))
	guess = divisors[0] * divisors[~0]
	correct = True
	for i in range(1, n // 2 + 1):
		if divisors[i] * divisors[~i] != guess:
			correct = False
			break
	if not correct:
		print(-1)
		continue
	cnt = 0
	x = 2
	while x * x < guess:
		if guess % x == 0:
			cnt += 2
		x += 1
	if x * x == guess:
		cnt += 1
	if cnt != n:
		print(-1)
	else:
		print(guess)


for _ in range(int(input())):
	n = int(input())
	divs = sorted(list(map(int, input().split())))
	x = divs[0] * divs[-1]
	divs2 = []
	i = 2
	while i * i < x:
		if not x % i:
			divs2.extend([x // i, i])
		i += 1
	if i * i == x:
		divs2.append(i)
	print(x if divs == sorted(divs2) else -1)


from collections import Counter
R = lambda : map(int, input().split())

def primefactors(n):
	f = 2
	while f * f <= n:
		while not n % f:
			yield f
			n //= f
		f += 1
	if n > 1:
		yield n
for _ in range(int(input())):
	n = int(input())
	dd = list(R())
	c = Counter()
	for d in dd:
		ct = Counter(primefactors(d))
		for k in ct:
			c[k] = max(c[k], ct[k])
	x = 1
	for (k, v) in c.items():
		x *= k ** v
	if x == max(dd):
		t = min(dd)
		x *= t
		c[t] += 1
	m = 1
	for v in c.values():
		m *= v + 1
	print(x if m == len(dd) + 2 else -1)


import math
q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = l[0] * l[-1]
	a = []
	for i in range(2, int(ans ** 0.5) + 2):
		if ans % i == 0:
			a.append(i)
			a.append(ans // i)
	a = list(set(a))
	a.sort()
	if a == l:
		print(ans)
	else:
		print(-1)


q = int(input())
while q:
	n = int(input())
	ar = input().split()
	br = list()
	for i in ar:
		br.append(int(i))
	br.sort()
	x = int(br[0]) * int(br[-1])
	i = 2
	a = x
	cr = list()
	while i * i <= x:
		if x % i == 0:
			cr.append(i)
			if i != a / i:
				cr.append(int(a / i))
		i = i + 1
	cr.sort()
	if cr == br:
		print(x)
	else:
		print(-1)
	q = q - 1


def _try_composite(a, d, n, s):
	if pow(a, d, n) == 1:
		return False
	for i in range(s):
		if pow(a, 2 ** i * d, n) == n - 1:
			return False
	return True

def is_prime(n, _precision_for_huge_n=16):
	if n in _known_primes:
		return True
	if any((n % p == 0 for p in _known_primes)) or n in (0, 1):
		return False
	(d, s) = (n - 1, 0)
	while not d % 2:
		(d, s) = (d >> 1, s + 1)
	if n < 1373653:
		return not any((_try_composite(a, d, n, s) for a in (2, 3)))
	if n < 25326001:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5)))
	if n < 118670087467:
		if n == 3215031751:
			return False
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7)))
	if n < 2152302898747:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11)))
	if n < 3474749660383:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13)))
	if n < 341550071728321:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17)))
	return not any((_try_composite(a, d, n, s) for a in _known_primes[:_precision_for_huge_n]))
_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
T = int(input())
for _ in range(T):
	n = int(input())
	x = set(map(int, input().split()))
	z = min(x) * max(x)
	zz = z
	cnt = 1
	for v in x:
		if z % v:
			print(-1)
			break
		elif is_prime(v):
			r = 1
			while not zz % v:
				zz //= v
				r += 1
			cnt *= r
	else:
		if cnt == n + 2 and zz == 1:
			print(z)
		else:
			print(-1)


import math

def function(n, nums):
	result = []
	x = min(nums) * max(nums)
	condition = True
	for i in range(len(nums)):
		if x % nums[i] != 0:
			condition = False
			break
	if condition:
		nums.append(1)
		nums.append(x)
		for i1 in range(1, math.floor(math.sqrt(x)) + 1):
			if x % i1 == 0:
				result.append(i1)
				result.append(int(x / i1))
		if set(nums) == set(result):
			print(x)
		if set(nums) != set(result):
			print(-1)
	if not condition:
		print(-1)
t = int(input())
for k1 in range(t):
	n = int(input())
	nums = list(map(int, input().rstrip().split()))
	function(n, nums)


import sys

def createfactors(n):
	s = set()
	i = 2
	while i * i <= n:
		if n % i == 0:
			s.add(i)
			s.add(n // i)
		i += 1
	return s

def answer(n, sd):
	x = min(sd) * max(sd)
	sf = createfactors(x)
	if sd == sf:
		return x
	else:
		return -1

def main():
	t = int(sys.stdin.readline())
	while t:
		n = int(sys.stdin.readline())
		sd = set(map(int, sys.stdin.readline().split()))
		print(answer(n, sd))
		t -= 1
	return
main()


def sieve():
	primes = [2]
	sieve = [True] * 1000000
	sieve[0] = sieve[1] = False
	for i in range(4, 1000000, 2):
		sieve[i] = False
	for i in range(3, 1000000, 2):
		if sieve[i]:
			primes.append(i)
			for j in range(2 * i, 1000000, i):
				sieve[j] = False
	return primes
primes = sieve()
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	val = x = min(ls) * max(ls)
	skip = False
	for v in ls:
		if x % v:
			print(-1)
			skip = True
			break
	if skip:
		continue
	divs = 1
	for p in primes:
		if p ** 2 > x:
			break
		e = 0
		while x % p == 0:
			(e, x) = (e + 1, x // p)
		divs *= e + 1
	if x > 1:
		divs *= 2
	print(val if divs == n + 2 else -1)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	s = set(d)
	s2 = set()
	x = max(d) * min(d)
	f = 1
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			a = i
			b = x // i
			s2.add(a)
			s2.add(b)
	if s == s2:
		print(x)
	else:
		print('-1')


def ans(arr):
	(i, j) = (0, len(arr) - 1)
	k = arr[i] * arr[j]
	while i <= j:
		if arr[i] * arr[j] != k:
			return -1
		i += 1
		j -= 1
	li = []
	i = 2
	while i * i <= k:
		if k % i == 0:
			li.append(i)
			if i * i != k:
				li.append(k // i)
		i += 1
	if not sorted(li) == arr:
		return -1
	return k
for _ in range(int(input())):
	n = int(input())
	arr = [int(s) for s in input().split()]
	arr.sort()
	print(ans(arr))


for Valerchiclox in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	c.sort()
	const = c[0] * c[-1]
	k = -1
	for i in c:
		if i * c[k] != const:
			const = -1
			break
		k -= 1
	if const == -1:
		print(const)
	else:
		s = 0
		for i in range(2, int(const ** 0.5) + 1):
			if const % i == 0:
				s += 1
		if s * 2 - n % 2 == n:
			print(const)
		else:
			print(-1)


import math
import sys
for _ in range(int(input())):
	numDivsors = int(input())
	numbers = [int(i) for i in input().split()]
	numbers = sorted(numbers)
	minNum = numbers[0]
	maxNum = numbers[len(numbers) - 1]
	answer = minNum * maxNum
	divisors = set()
	for i in range(2, math.ceil(math.sqrt(answer)) + 1):
		if answer % i == 0:
			if i == answer / i:
				divisors.add(i)
			else:
				divisors.add(i)
				divisors.add(int(answer / i))
	divisors = sorted(divisors)
	if len(divisors) != len(numbers):
		print('-1')
		continue
	else:
		check = True
		for i in range(len(divisors)):
			if divisors[i] != numbers[i]:
				print('-1')
				check = False
				break
		if check:
			print(answer)


def f(n):
	ans = set()
	for i in range(2, round(n ** 0.5) + 1):
		if n % i == 0:
			ans.add(i)
			ans.add(n // i)
	return sorted(list(ans))
for _ in range(int(input())):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	result = l[0] * l[-1]
	suggestion = f(result)
	if suggestion != l:
		print(-1)
	else:
		print(result)


def div(guess, n, primes):
	r = 1
	for p in primes:
		if guess < p:
			break
		count = 0
		while guess % p == 0:
			count += 1
			guess = guess // p
		r = r * (count + 1)
	return r

def main():
	import math
	t = int(input())
	aux_primes = [True] * (10 ** 6 + 1)
	aux_primes[0] = aux_primes[1] = False
	for i in range(2, int(math.sqrt(10 ** 6 + 1))):
		if aux_primes[i]:
			for j in range(i * 2, 10 ** 6 + 1, i):
				aux_primes[j] = False
	primes = [i for i in range(10 ** 6 + 1) if aux_primes[i]]
	while t:
		t -= 1
		n = int(input())
		arr = list(map(int, input().split()))
		guess = min(arr) * max(arr)
		ok = not any((guess % i for i in arr))
		if ok and n + 2 == div(guess, n, primes):
			print(guess)
		else:
			print(-1)
main()


n = int(input())
for l in range(n):
	n1 = int(input())
	a = [int(i) for i in input().split()]
	a.sort()
	ans = a[0] * a[-1]
	a = set(a)
	i = 2
	t = 0
	lol = 1
	for i in range(2, int(ans ** 0.5) + 1):
		if ans % i == 0:
			k = ans // i
			if i not in a or k not in a:
				lol = 0
				print(-1)
				break
			if i != k:
				t += 2
			else:
				t += 1
		i += 1
	if n1 != t and lol and (len(a) != 1):
		lol = 0
		print(-1)
	if lol:
		print(ans)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = min(a) * max(a)
	d = []
	for i in range(2, int(b ** 0.5) + 1):
		if b % i == 0:
			d.append(i)
			d.append(b // i)
	d = list(set(d))
	d.sort()
	a = list(set(a))
	a.sort()
	if a == d:
		print(b)
	else:
		print('-1')


import math
t = int(input())
for _ in range(t):
	n = int(input())
	d = [int(x) for x in input().split()]
	mmin = None
	mmax = None
	for x in d:
		if mmin is None or x < mmin:
			mmin = x
		if mmax is None or x > mmax:
			mmax = x
	cand = mmin * mmax
	divs = set()
	for x in range(2, int(math.sqrt(cand)) + 3):
		if cand > x and cand % x == 0:
			divs.add(x)
			divs.add(cand // x)
	if len(divs) != len(d):
		print(-1)
		continue
	bad = False
	for x in d:
		if x not in divs:
			bad = True
			break
	if bad:
		print(-1)
	else:
		print(cand)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	ans = a[0] * a[-1]
	for i in range(n):
		if a[i] * a[n - i - 1] != ans:
			ans = -1
			break
	if ans == -1:
		print(ans)
		continue
	s = set(a)
	p = 2
	while p * p <= ans:
		if ans % p == 0:
			if p not in s or ans // p not in s:
				ans = -1
				break
		p += 1
	print(ans)


def make_divisors(n):
	divisors = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
n = int(input())
for i in range(n):
	l = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	tmin = arr[0]
	tmax = arr[-1]
	x = tmin * tmax
	check = make_divisors(x)
	cl = len(check)
	if l != cl:
		print(-1)
	else:
		for i in range(l):
			if arr[i] != check[i]:
				print(-1)
				break
		else:
			print(x)


import math
n = int(input())
result = []

def divisors(n):
	count = 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				count += 1
			else:
				count += 2
	return count
for i in range(n):
	n1 = int(input())
	n2 = list(list(map(int, input().split())))
	n2.sort()
	a1 = n2[0] * n2[-1]
	final = True
	for i in range(len(n2)):
		if n2[i] * n2[len(n2) - 1 - i] != a1:
			final = False
			break
	if n1 == 1 and n2[0] == 1:
		result.append(1)
	elif final and n1 == divisors(a1):
		result.append(a1)
	else:
		result.append(-1)
for i in result:
	print(i)


import sys
import itertools
import math
import collections
from collections import Counter

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
pr = sieve(10 ** 6)

def divn(n):
	res = 1
	for i in pr:
		t = 1
		while n % i == 0:
			t += 1
			n = n // i
		res *= t
		if n == 1:
			return res
t = ii()
for _ in range(t):
	n = ii()
	d = sorted(li())
	r = d[0] * d[n - 1]
	if divn(r) - 2 != n:
		print(-1)
		continue
	print(-1) if any((d[i] * d[n - 1 - i] != r for i in range(1, n // 2 + 1))) else print(r)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = min(l) * max(l)
	i = 2
	ll = []
	while i * i < x:
		if x % i == 0:
			ll.append(i)
			ll.append(x // i)
		i += 1
	if i * i == x:
		ll.append(i)
	ll.sort()
	l.sort()
	for i in range(n):
		if ll[i] != l[i]:
			print(-1)
			break
	else:
		print(x)


import math
n = int(input())
for i in range(n):
	divs = set()
	h = int(input())
	l = list(map(int, input().split()))[:h]
	l.sort()
	x = l[0] * l[-1]
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			divs.add(i)
			divs.add(x // i)
	divs = sorted(list(divs))
	if divs == l:
		print(x)
	else:
		print(-1)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()

def divCount(n):
	i = 1
	li = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				li.append(i)
			else:
				li.append(i)
				li.append(n // i)
		i = i + 1
	return li
t = intIn()
while t > 0:
	t -= 1
	n = intIn()
	d = listIn()
	d = sorted(d)
	arr = [0] * (10 ** 6 + 5)
	arr[1] = 1
	for ele in d:
		arr[ele] = 1
	flag = False
	ans = d[0] * d[-1]
	res = []
	for ele in d:
		l = divCount(ele)
		for ll in l:
			if arr[ll] == 0:
				flag = True
				break
		if flag:
			break
		res += l
	if not flag:
		res = list(set(res))
		res.sort()
		d.insert(0, 1)
		if res != d:
			print(-1)
		else:
			d.append(ans)
			n = len(d)
			if n % 2 == 0:
				c = n // 2
			else:
				c = n // 2 + 1
			li2 = []
			f2 = 0
			for i in range(c):
				m = d[i] * d[n - i - 1]
				if m != ans:
					f2 = 1
					break
				li2.append(m)
			if f2:
				print(-1)
			else:
				print(ans)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mi = int(9999999)
	ma = int(1)
	for j in range(n):
		mi = min(mi, a[j])
		ma = max(ma, a[j])
	q = mi * ma
	b = bool(1)
	j = 2
	while j * j <= q:
		if q % j == 0 and (not j in a or not int(q / j) in a):
			b = 0
			break
		j += 1
	if b:
		for j in range(n):
			if q % a[j] or not int(q / a[j]) in a:
				b = bool(0)
				break
	if b:
		print(q)
	else:
		print(-1)


tc = int(input())
while tc != 0:
	tc -= 1
	n = int(input())
	ar = list(map(int, input().split()))
	ar.sort()
	if 1 in ar:
		print(-1)
		continue
	hs = set(ar)
	i = 2
	ps = set()
	ans = ar[0] * ar[-1]
	while i * i <= ans:
		if ans % i == 0:
			ps.add(ans // i)
			ps.add(i)
		i += 1
	if ps != hs:
		print('-1')
	else:
		print(ar[0] * ar[-1])


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())
from collections import Counter

def get_ls(n):
	result = []
	i = 2
	while i < n:
		if n % i == 0:
			n /= i
			result.append(i)
		else:
			i += 1
	result.append(int(n))
	return result
t = f()
for i in range(t):
	n = f()
	cl = sorted(f(2))
	x = cl[0] * cl[-1]
	res = get_ls(x)
	count = 1
	ans = 1
	for j in range(len(res) - 1):
		if res[j] == res[j + 1]:
			count += 1
		else:
			ans = ans * (count + 1)
			count = 1
	ans = ans * (count + 1)
	if ans != n + 2:
		print(-1)
	else:
		st = False
		for i in range(n):
			if cl[i] * cl[n - i - 1] != x:
				st = True
				break
		if st:
			print(-1)
		else:
			print(x)


def out(n):
	(i, lst) = (2, list())
	while i * i <= n:
		if n % i == 0:
			lst.append(i)
			lst.append(n // i)
		i += 1
	return lst

def check():
	n = int(input())
	d = sorted([int(j) for j in input().split()])
	x = d[0] * d[-1]
	(d1, d2) = (out(d[0]), out(d[-1]))
	if d1:
		return -1
	s = set(d2 + [d[0], d[-1]]) | set((d[0] * i for i in d2))
	if set(d) == s:
		return x
	return -1
t = int(input())
for i in range(t):
	print(check())


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num
from math import floor

def printDivisors(n):
	ans = set()
	i = 1
	for i in range(1, floor(n ** 0.5) + 2):
		if n % i == 0:
			if n / i == i:
				ans.add(i)
			else:
				ans.add(i)
				ans.add(n // i)
		i = i + 1
	return list(ans)

def findN(div):
	div = sorted(div)
	N = div[0] * div[-1]
	factors = sorted(printDivisors(N))[1:-1]
	for i in range(len(factors)):
		if factors[i] != div[i]:
			return -1
	return N
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(findN(lst))


for i in ' ' * int(input()):
	n = int(input())
	(*a,) = sorted(map(int, input().split()))
	s = a[0] * a[-1]
	a = {*a}
	d = set()
	i = 2
	while i * i <= s:
		if s % i == 0:
			d |= {i, s // i}
		i += 1
	if a != d:
		s = -1
	print(s)


from sys import setcheckinterval, stdin, setrecursionlimit
setcheckinterval(1000)
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
t = iin()
while t:
	t -= 1
	n = iin()
	a = lin()
	x = min(a) * max(a)
	na = []
	i = 2
	while i * i < x:
		if x % i == 0:
			na.append(i)
			na.append(x // i)
		i += 1
	else:
		if i * i == x:
			na.append(i)
	a.sort()
	na.sort()
	if a == na:
		print(x)
	else:
		print(-1)


t = int(input())
l = []

def almost(x):
	divisors = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			divisors.append(i)
			if i ** 2 != x:
				divisors.append(x // i)
	return sorted(divisors)
for query in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	L.sort()
	if L == almost(L[0] * L[-1]):
		print(L[0] * L[-1])
	else:
		print(-1)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN():
	return list(numIN())

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def res(ans, t):
	print('Case #{}: {} {}'.format(t, ans[0], ans[1]))

def divi(n):
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
for _ in range(int(input())):
	n = int(input())
	a = arrIN()
	a.sort()
	x = a[0] * a[-1]
	fl = [0] * MAXN
	f = 1
	for i in a:
		fl[i] = 1
	fl[1] = 1
	for j in a:
		l = divi(j)
		for i in l:
			if not fl[i]:
				print(-1)
				f = 0
				break
		if not f:
			break
	if f:
		for i in range(n // 2 + 1):
			if a[i] * a[n - i - 1] != x:
				print(-1)
				f = 0
				break
	if f:
		print(x)


def sigma0(n):
	r = 1
	c = 2
	while c * c <= n:
		p = 0
		while n % c == 0:
			p += 1
			n /= c
		r *= p + 1
		c += 1
	if n > 1:
		r *= 2
	return r
T = int(input())
while T > 0:
	n = int(input())
	a = sorted(list(map(int, input().split())))
	k = a[0] * a[-1]
	res = k
	for i in range(n // 2 + 1):
		if a[i] * a[-i - 1] != k:
			res = -1
			break
	if res != -1 and sigma0(res) != n + 2:
		res = -1
	print(res)
	T -= 1


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def facts(n):
	ans = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i == n ** 0.5:
				ans += 1
			else:
				ans += 2
	return ans
t = I()
for _ in range(t):
	n = I()
	l = L()
	l.sort()
	i = 0
	j = n - 1
	p = l[0] * l[-1]
	if facts(p) - 2 != n:
		print(-1)
	else:
		f = 0
		while i <= j:
			q = l[i] * l[j]
			if q != p:
				print(-1)
				f = 1
				break
			i += 1
			j -= 1
		if f == 0:
			print(p)


def get_case():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	s = set()
	candidate = min(a) * max(a)
	i = 2
	while i * i <= candidate:
		if candidate % i == 0:
			s.add(i)
			s.add(candidate // i)
		i += 1
	if s == set(a):
		return candidate
	return -1

def go():
	t = int(input())
	output = ''
	for i in range(t):
		output += '{}\n'.format(get_case())
	return output
print(go())


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = a[0] * a[-1]
	flag = True
	for i in range((n + 1) // 2):
		if a[i] * a[-1 - i] != x:
			flag = False
			break
	if flag == False:
		print('-1')
		continue
	ant = 0
	for i in range(2, int(x ** (1 / 2)) + 1):
		if x % i == 0:
			ant += 2
			if i * i == x:
				ant -= 1
	if ant == n:
		print(x)
	else:
		print('-1')


from math import gcd, sqrt

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def ii():
	return int(input())

def lcm(a, b):
	return a * b // gcd(a, b)

def isprime(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	x = a[0]
	mul = 1
	for i in a:
		mul *= i
	for i in range(1, n):
		x = lcm(x, a[i])
	if mul == x:
		if n == 2:
			b = []
			f = 0
			if isprime(a[0]) and isprime(a[1]):
				print(mul)
			else:
				print('-1')
		elif n == 1:
			if isprime(x):
				print(x * x)
			else:
				print('-1')
		else:
			print('-1')
		continue
	b = []
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			if i == x // i:
				b.append(i)
			else:
				b.append(i)
				b.append(x // i)
	f = 0
	for i in b:
		if i not in a:
			f = 1
			break
	if f:
		print('-1')
	elif x != max(a):
		print(x)
	else:
		x = x * min(b)
		b = []
		for i in range(2, int(sqrt(x)) + 1):
			if x % i == 0:
				if i == x // i:
					b.append(i)
				else:
					b.append(i)
					b.append(x // i)
		f = 0
		for i in b:
			if i not in a:
				f = 1
				break
		if f:
			print('-1')
		else:
			print(x)


from collections import Counter

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(a):
	result = 1
	ca = a.copy()
	a.sort()
	primes = []
	for i in range(len(a)):
		if a[i] == 1:
			continue
		else:
			result *= a[i]
			if not isPrime(a[i]):
				return -1
			primes.append(a[i])
			for j in range(i + 1, len(a)):
				if a[j] % a[i] == 0:
					a[j] = a[j] // a[i]
	c = Counter(primes)
	la = 1
	if result == max(ca):
		ma = min(ca)
		result = result * ma
		c[ma] += 1
	for v in c.values():
		la *= v + 1
	la = la - 2
	if la != len(a):
		return -1
	return result
n = int(input())
for i in range(1, n + 1):
	k = int(input())
	a = list(map(int, input().split()))
	x = solve(a)
	print(x)


Q = int(input())

def decompose(x):
	ans = {}
	cx = x
	d = 2
	while d * d <= cx:
		t = 0
		while x % d == 0:
			t += 1
			x = x // d
		if t > 0:
			ans[d] = t
		d += 1
	if x > 1:
		ans[x] = 1
	return ans

def fastpow(x, p):
	if p == 0:
		return 1
	ans = fastpow(x, p // 2)
	ans *= ans
	if p % 2 == 1:
		ans *= x
	return ans

def makePrimePower(divs):
	primePowers = {}
	for d in divs:
		ppows = decompose(d)
		for key in ppows:
			if key not in primePowers:
				primePowers[key] = ppows[key]
			else:
				primePowers[key] = max(primePowers[key], ppows[key])
	return primePowers

def solve(divs):
	primePowers = makePrimePower(divs)
	if len(primePowers) == 1:
		primePowers[list(primePowers.keys())[0]] += 1
	nrdivs = 1
	for key in primePowers:
		nrdivs *= primePowers[key] + 1
	if len(divs) + 2 != nrdivs:
		return -1
	x = 1
	for key in primePowers:
		x *= fastpow(key, primePowers[key])
	if x in divs:
		return -1
	return x
for x in range(Q):
	N = int(input())
	divs = list(map(int, input().split()))
	print(solve(divs))


import math

def Solve_Querie(divisors):
	x = min(divisors) * max(divisors)
	x_divisors = []
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			x_divisors.append(i)
			if i * i != x:
				x_divisors.append(x / i)
	if set(divisors) == set(x_divisors):
		return x
	return -1

def Tester(condition):
	solution = []
	if condition == 0:
		n = int(input())
		for i in range(0, n):
			input()
			divisors = []
			for j in input().split():
				divisors.append(int(j))
			solution.append(Solve_Querie(divisors))
			i += 1
	for i in solution:
		print(i)
Tester(0)


def f(num):
	q = 2
	count = 0
	while q * q < num:
		if num % q == 0:
			count += 2
		q += 1
	if q * q == num:
		count += 1
	return count
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	num = a[0] * a[-1]
	z = False
	for elem in a:
		if num % elem != 0:
			z = True
			break
	if not z and f(num) != n:
		z = True
	if z:
		print(-1)
	else:
		print(num)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		(v, s, d) = (max(arr) * min(arr), set(), 2)
		while d * d <= v:
			if v % d == 0:
				s.add(d)
				s.add(v // d)
			d += 1
		print(v if s == set(arr) else -1)
solve()


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
for xyz in range(0, int(input())):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	f = 1
	r = n - 2
	val = l[0] * l[-1]
	ans = True
	while f <= r:
		if val == l[f] * l[r]:
			f += 1
			r -= 1
		else:
			ans = False
			break
	if ans:
		s = set()
		root = int(val ** 0.5)
		for i in range(2, root + 2):
			if val % i == 0:
				s.add(i)
				s.add(val // i)
		if s == set(l):
			print(val)
		else:
			print(-1)
	else:
		print(-1)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	x = d[0] * d[-1]
	y = x
	if x in d:
		print(-1)
	l = []
	flag = True
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			cnt = 0
			while x % i == 0:
				x //= i
				cnt += 1
			l.append(cnt)
			if len(l) > len(d):
				flag = False
				break
	if x > 1 and x != y:
		l.append(1)
	ll = 1
	for c in l:
		ll *= c + 1
	ll -= 2
	if ll != len(d):
		flag = False
	for i in range(n):
		if y % d[i]:
			flag = False
	if flag:
		print(y)
	else:
		print(-1)


import sys
from math import sqrt

def main():
	n = int(input())
	for i in range(n):
		num = int(sys.stdin.readline())
		lst = list(map(int, sys.stdin.readline().split()))
		k = 1
		new = max(lst) * min(lst)
		for i in lst:
			if new % i != 0:
				k = 0
				break
		if k:
			isum = 0
			new1 = int(sqrt(new))
			while new1 > 1:
				if new1 * new1 == new:
					isum += 1
				elif new % new1 == 0:
					isum += 2
				new1 -= 1
			if isum != len(lst):
				print('-1')
			else:
				print(new)
		else:
			print('-1')
main()


from math import sqrt

def dels(x):
	dels = set()
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			dels.add(i)
			dels.add(x // i)
	return dels
for i in range(int(input())):
	n = int(input())
	a = set((int(i) for i in input().split()))
	x = min(a) * max(a)
	if dels(x) == a:
		print(x)
	else:
		print(-1)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
for _ in range(t()):
	n = t()
	a = list(ll())
	a.sort()
	x = a[0] * a[-1]
	l = set()
	i = 2
	while i * i <= x:
		if x % i == 0:
			l.add(x // i)
			l.add(i)
		i += 1
	if a == sorted(l):
		print(x)
	else:
		print(-1)


from math import sqrt

def count(n):
	ans = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				ans = ans + 1
			else:
				ans = ans + 2
	return ans
for _ in range(int(input())):
	n = int(input())
	l = [int(s) for s in input().split()]
	l.sort()
	ans = l[0] * l[-1]
	if count(ans) - 2 != n:
		print(-1)
		continue
	for i in range(1, n - 1):
		an1 = l[i] * l[-i - 1]
		if an1 != ans:
			ans = -1
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = min(l) * max(l)
	divofx = []
	d = 2
	while d * d <= x:
		if x % d == 0:
			divofx.append(d)
			if x // d != d:
				divofx.append(x // d)
		d += 1
	l.sort()
	divofx.sort()
	if l == divofx:
		print(x)
	else:
		print(-1)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = inar()
		arr.sort()
		num = arr[0] * arr[-1]
		divisors = []
		for i in range(2, int(num ** 0.5) + 1):
			if num % i == 0 and i != num // i:
				divisors.append(i)
				divisors.append(num // i)
			elif num % i == 0 and num // i == i:
				divisors.append(i)
		divisors.sort()
		if divisors == arr:
			print(num)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def find_divisors(n):
	divs = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			divs.append(i)
			if i != n // i:
				divs.append(n // i)
	divs.sort()
	return divs
t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	x = d[0] * d[-1]
	for i in range((n + 1) // 2):
		if x != d[i] * d[n - 1 - i]:
			print(-1)
			break
	else:
		d2 = find_divisors(x)
		if d == d2:
			print(x)
		else:
			print(-1)


import math
from decimal import *
import random

def facts(n):
	ans = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	return list(dict.fromkeys(ans))
for _ in range(int(input())):
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	if n == 1:
		if len(facts(arr[0] * arr[0])) == 1:
			print(arr[0] * arr[0])
		else:
			print(-1)
	else:
		ok = True
		no = arr[0] * arr[-1]
		(p1, p2) = (1, n - 2)
		while p1 <= p2:
			if arr[p1] * arr[p2] != no:
				ok = False
				break
			else:
				p1 += 1
				p2 -= 1
		if ok and len(facts(no)) == n:
			print(no)
		else:
			print(-1)


def divisors(x):
	ans = []
	for i in range(2, int(x ** 0.5) + 2):
		if x % i == 0:
			ans.append(i)
			ans.append(x // i)
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	d = [int(j) for j in input().split()]
	x = max(d) * min(d)
	ans = x
	for j in range(n):
		if x % d[j] != 0:
			break
	if ans > 0 and set(d) == set(divisors(ans)):
		print(ans)
	else:
		print('-1')


def get_number_unique_factors(num):
	factors = 0
	limit = int(num) ** 0.5
	i = 2
	while i <= limit:
		if num % i == 0:
			factors += 1
			if num / i != i:
				factors += 1
		i += 1
	return factors
queries = int(input())
for _ in range(queries):
	length = int(input())
	nums = list(map(int, input().split()))
	nums.sort()
	target_number = nums[0] * nums[-1]
	halfway = int(length / 2 - 1) if not length & 1 else int(length / 2)
	exit = False
	for i in range(halfway + 1):
		if nums[i] * nums[length - i - 1] != target_number:
			exit = True
			break
	if exit:
		print(-1)
		continue
	if get_number_unique_factors(target_number) != length:
		print(-1)
	else:
		print(target_number)


t = int(input())
for j in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if n % 2 == 1:
		res = l[n // 2] ** 2
	else:
		res = l[0] * l[n - 1]
	f = []
	r = int(res ** 0.5) + 1
	for i in range(2, r):
		if res % i == 0:
			f.append(i)
			f.append(int(res / i))
	ff = True
	f.sort()
	f = list(set(f))
	for i in range(n):
		if f[i] != l[i]:
			ff = False
			break
	if ff:
		print(res)
	else:
		print('-1')


t = int(input())
for j in range(t):
	n = int(input())
	ds = list(map(int, input().split()))
	st = set(ds)
	candidate = int(min(ds)) * int(max(ds))
	broken = False
	for i in range(2, 1 + int(pow(candidate, 0.5))):
		if candidate % i == 0:
			x = candidate // i
			if i not in st or x not in st:
				broken = True
				break
			else:
				st -= {i, x}
	if len(st) != 0 or broken:
		print(-1)
	else:
		print(candidate)


for j in range(int(input())):
	numOfDividers = int(input())
	dividers = list(map(int, input().split()))
	number = min(dividers) * max(dividers)
	for i in range(2, int(number ** 0.5) + 1):
		if number % i == 0 and (i not in dividers or number // i not in dividers):
			print(-1)
			break
	else:
		for i in dividers:
			if number % i != 0:
				print(-1)
				break
		else:
			print(number)


from sys import *
from math import *
from collections import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	if n % 2 == 0:
		mid = n // 2
	else:
		mid = n // 2 + 1
	x = a[0] * a[n - 1]
	f = 0
	for i in range(1, mid):
		if a[i] * a[n - i - 1] != x:
			f = 1
			break
	if f == 0:
		b = []
		for i in range(2, int(sqrt(x)) + 1):
			if x % i == 0:
				b.append(i)
				b.append(x // i)
		b.sort()
		c = [b[0]]
		for i in range(1, len(b)):
			if b[i] != b[i - 1]:
				c.append(b[i])
		if c == a:
			print(x)
		else:
			print(-1)
	else:
		print(-1)


import math

def factors(m):
	b = []
	for i in range(2, int(math.sqrt(m)) + 1):
		if m % i == 0:
			b.append(i)
			b.append(m // i)
	return set(b)
t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	d = sorted(d)
	d = list(set(d))
	ans = d[0] * d[-1]
	a = factors(ans)
	if a == set(d):
		print(ans)
	else:
		print(-1)


def divisors(n):
	res = set()
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			res.add(i)
			res.add(n // i)
	return res

def solve():
	for _ in range(int(input())):
		N = int(input())
		D = set([int(k) for k in input().split()])
		ans = max(D) * min(D)
		if divisors(ans) != D:
			print(-1)
			continue
		print(ans)

def __starting_point():
	solve()
__starting_point()


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(2, int(n ** 0.5) + 1) if n % i == 0)))
T = int(input())
for t in range(0, T):
	a = int(input())
	K = list(map(int, input().strip().split()))[:a]
	K.sort()
	X = K[0] * K[a - 1]
	K = set(K)
	C = factors(X)
	if C == K:
		print(X)
	else:
		print(-1)


def get_case():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	x = min(a) * max(a)
	v = set()
	d = 2
	while d * d <= x:
		if 0 == x % d:
			v.add(d)
			v.add(x / d)
		d += 1
	return x if v == set(a) else -1

def go():
	t = int(input())
	output = ''
	for i in range(t):
		output += '{}\n'.format(get_case())
	return output
print(go())


N = 1000000 + 7
v = [True] * N
v[0] = v[1] = False
for (i, stat) in enumerate(v):
	if stat:
		for n in range(i * i, N, i):
			v[n] = False
p = []
for (i, stat) in enumerate(v):
	if stat:
		p.append(i)
t = int(input())
for tc in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	sd = set(d)
	d = sorted(d)
	f = []
	g = dict()
	for e in d:
		num = e
		if v[num]:
			gl = [1]
			while num in sd:
				gl.append(num)
				num = num * e
			num = num // e
			f.append(num)
			g[e] = gl
	brake = False
	glast = [1]
	for (key, gl) in g.items():
		gtemp = []
		for e1 in gl:
			for e2 in glast:
				gtemp.append(e1 * e2)
				if len(gtemp) > len(d) + 2:
					brake = True
					break
			if brake:
				break
		if brake:
			break
		glast = gtemp
	if brake:
		print(-1)
		continue
	glast = sorted(glast)
	if len(glast) > 0:
		del glast[0]
	else:
		print(-1)
		continue
	if len(glast) > 0:
		del glast[-1]
	else:
		print(-1)
		continue
	ok = True
	if len(d) != len(glast):
		ok = False
	else:
		for i in range(n):
			if d[i] != glast[i]:
				ok = False
				break
	if ok:
		r = 1
		for a in f:
			r = r * a
		print(r)
	else:
		yes = True
		if len(g) == 1 and v[d[0]]:
			ggen = [d[0]]
			while ggen[-1] < d[-1]:
				ggen.append(ggen[-1] * d[0])
			if n != len(ggen):
				yes = False
			else:
				for i in range(0, n):
					if d[i] != ggen[i]:
						yes = False
						break
			if yes:
				print(d[0] * d[-1])
			else:
				print(-1)
		else:
			print(-1)


from math import gcd
import math
mod = 10 ** 9 + 7

def divisors(i):
	arr = []
	g = math.sqrt(i)
	g = math.floor(g)
	for j in range(2, g + 1):
		if i % j == 0:
			if i // j == j:
				arr.append(j)
			else:
				arr.append(i // j)
				arr.append(j)
	return arr
t = int(input())
for ii in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	mota = min(a) * max(a)
	if set(a) == set(divisors(mota)):
		print(mota)
	else:
		print(-1)


def divisors(X):
	res = set([])
	for i in range(1, X + 1):
		if i * i > X:
			break
		elif X % i == 0:
			res.add(i)
			res.add(X // i)
	if 1 in res:
		res.remove(1)
	if X in res:
		res.remove(X)
	res = list(res)
	res.sort()
	return tuple(res)

def solve():
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	if len(d) % 2 != 0:
		ans = d[n // 2] ** 2
	else:
		ans = d[0] * d[-1]
	if tuple(d) == divisors(ans):
		print(ans)
	else:
		print(-1)
	return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


def divisors(num):
	divisors = []
	for i in range(1, int(num ** 0.5) + 1):
		if num % i == 0:
			divisors.append(i)
			if i != num // i:
				divisors.append(num // i)
	return divisors
T = int(input())
for t in range(T):
	N = int(input())
	d_list = list(map(int, input().split()))
	d_list.sort()
	target = min(d_list) * max(d_list)
	res = divisors(target)
	res.remove(1)
	res.remove(target)
	res.sort()
	if len(d_list) == len(res):
		flg = True
		for i in range(len(res)):
			if d_list[i] == res[i]:
				continue
			else:
				print(-1)
				flg = False
				break
		if flg:
			print(target)
	else:
		print(-1)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	num = a[0] * a[-1]
	b = list()
	for i in range(2, int(math.sqrt(num)) + 1):
		if num % i == 0:
			b.append(i)
			if i * i != num:
				b.append(num // i)
	b.sort()
	for i in range(n):
		if len(a) != len(b):
			num = -1
			break
		if a[i] != b[i]:
			num = -1
			break
	print(num)


def calculateNoOFactors(n):
	c = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != n // i:
				c += 2
			else:
				c += 1
	return c
t = int(input())
for i in range(t):
	n = int(input())
	k = list(map(int, input().split()))
	k.sort()
	l = 0
	r = n - 1
	z = set([])
	d = 0
	while l <= r:
		z.add(k[l] * k[r])
		if len(z) > 1:
			print(-1)
			d = 1
			break
		l += 1
		r -= 1
	key = calculateNoOFactors(list(z)[0])
	if d != 1:
		if key - 2 != n:
			print(-1)
		else:
			print(list(z)[0])


for _ in range(int(input())):
	n = int(input())
	d = sorted(list(map(int, input().split())))
	ans = d[0] * d[-1]
	temp = []
	for i in range(2, int(ans ** 0.5 + 1)):
		if ans % i == 0:
			temp.append(i)
			if i != ans // i:
				temp.append(ans // i)
	temp.sort()
	if temp == d:
		print(ans)
	else:
		print(-1)


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2, floor
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def all_factors(n):
	(small, large) = (0, 0)
	count = 0
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small = i
			large = n // i
			count += 2
	if small == large:
		count -= 1
	return count

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T > 0:
	n = int(input())
	Arr = get_array()
	Arr.sort()
	length = len(Arr)
	if length == 1:
		if is_prime(Arr[0]):
			print(Arr[0] * Arr[0])
		else:
			print(-1)
	elif length == 2:
		x = Arr[0] * Arr[1]
		if is_prime(Arr[0]) and is_prime(Arr[1]):
			print(x)
		elif is_prime(Arr[0]) and Arr[1] == Arr[0] * Arr[0]:
			print(x)
		else:
			print(-1)
	elif not length & 1:
		x = Arr[0] * Arr[-1]
		flag = 0
		for i in range(1, length // 2):
			if Arr[i] * Arr[length - i - 1] != x:
				flag = 1
				break
		if flag == 0:
			if all_factors(x) - 2 == n:
				print(x)
			else:
				print(-1)
		else:
			print(-1)
	elif length & 1:
		x = Arr[length // 2] * Arr[length // 2]
		flag = 0
		for i in range(length // 2):
			if Arr[i] * Arr[length - i - 1] != x:
				flag = 1
				break
		if flag == 0:
			if all_factors(x) - 2 == n:
				print(x)
			else:
				print(-1)
		else:
			print(-1)
	T -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = min(a) * max(a)
	l = set()
	d = 2
	while d * d <= x:
		if not x % d:
			l.add(d)
			l.add(x // d)
		d += 1
	print(x if l == set(a) else -1)


for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	ans = a[0] * a[-1]
	b = set(a)
	r = []
	for i in range(2, int(ans ** 0.5 + 1)):
		if ans % i == 0:
			r.append(i)
			r.append(ans // i)
	if set(r) != b:
		print(-1)
	else:
		print(ans)


t = int(input())
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009]
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	mini = min(l)
	maksi = max(l)
	a = mini * maksi
	c = 0
	for d in l:
		if a % d != 0:
			c = 1
			break
	if c == 1:
		print(-1)
		continue
	fac = []
	i = 2
	for p in prime:
		if p > max(maksi, mini):
			break
		if maksi % p != 0 and mini % p != 0:
			continue
		chuj = 0
		while True:
			if maksi % p == 0:
				maksi = maksi // p
				chuj += 1
			else:
				break
		while True:
			if mini % p == 0:
				mini = mini // p
				chuj += 1
			else:
				break
		if chuj > 0:
			fac.append([p, chuj])
	czek = 1
	diwi = 1
	for f in fac:
		diwi = diwi * (f[1] + 1)
	if mini == maksi:
		if mini > 1:
			diwi *= 3
	else:
		if mini > 1:
			diwi *= 2
		if maksi > 1:
			diwi *= 2
	if diwi - 2 == n:
		print(a)
	else:
		print(-1)


t = int(input())
for q in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	array.sort()
	x = array[0] * array[-1]
	newarray = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			newarray.append(i)
			if i != x // i:
				newarray.append(x // i)
		i += 1
	newarray.sort()
	if array == newarray:
		print(x)
	else:
		print(-1)


def getDivs(n):
	ret = []
	d = 2
	while d * d <= n:
		if n % d == 0:
			ret.append(d)
			if d * d != n:
				ret.append(n // d)
		d += 1
	return sorted(ret)
for _ in range(int(input())):
	input()
	divs = sorted(map(int, input().split()))
	ans = divs[0] * divs[-1]
	print(ans if getDivs(ans) == divs else -1)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = a[0] * a[-1]
	fact = []
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			fact.append(i)
			if i != sqrt(x):
				fact.append(x // i)
	fact.sort()
	if fact == a:
		print(x)
	else:
		print(-1)


def ld(n):
	(i, v) = (2, [])
	while i * i <= n:
		if n % i == 0:
			v.append(i)
			v.append(n // i)
		i += 1
	return v

def f():
	(n, d) = (int(input()), sorted(map(int, input().split())))
	x = d[0] * d[-1]
	(d1, d2) = (ld(d[0]), ld(d[-1]))
	if d1:
		return -1
	s = set(d2 + [d[0], d[-1]]) | set((d[0] * d2i for d2i in d2))
	return x if set(d) == s else -1
for t in range(int(input())):
	print(f())


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


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def divisors(n):
	v = int(n ** 0.5)
	d = []
	for i in range(2, v + 1):
		if n % i == 0:
			d.append(i)
			v1 = n // i
			if v1 != i:
				d.append(v1)
	return sorted(d)
cases = int(input())
for t in range(cases):
	n = int(input())
	d = list(map(int, input().split()))
	d = sorted(d)
	v = d[0] * d[-1]
	div = divisors(v)
	if d == div:
		print(v)
	else:
		print(-1)


from collections import Counter, defaultdict, deque
import heapq as hq
from itertools import count, islice

def divisors(n):
	i = 1
	divs = set()
	while i * i <= n:
		if n % i == 0:
			divs.add(i)
			if i * i != n:
				divs.add(n // i)
		i += 1
	return divs
import math
import sys
input = sys.stdin.readline
tt = int(input())
for test in range(tt):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort()
	num = arr[0] * arr[-1]
	fail = False
	alld = set()
	for el in arr:
		alld |= divisors(el)
	if len(alld) - 1 > len(arr):
		print(-1)
		continue
	for i in range(1, (len(arr) + 1) // 2):
		a = arr[i]
		b = arr[n - i - 1]
		if a * b != num:
			fail = True
			break
	if fail:
		print(-1)
	else:
		print(num)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	f = a[0] * a[-1]
	D = set()
	for k in range(2, int(f ** 0.5) + 1):
		if f % k == 0:
			D.add(k)
			D.add(f // k)
	if set(a) == D:
		print(f)
	else:
		print(-1)


from math import sqrt
from itertools import product
from operator import mul
from functools import reduce

def prime_factors(n):
	f = []
	for d in range(2, int(sqrt(n)) + 1):
		while n % d == 0:
			f.append(d)
			n //= d
	if n > 1:
		f.append(n)
	return f

def factors(x, y):
	f = prime_factors(x) + prime_factors(y)
	l = []
	for d in set(f):
		l.append([d ** p for p in range(f.count(d) + 1)])
	return set((reduce(mul, d, 1) for d in product(*l)))
for _ in range(int(input())):
	n = int(input())
	d = [int(x) for x in input().split()]
	(x, y) = (min(d), max(d))
	c = factors(x, y)
	if c == set(d + [1, x * y]):
		print(x * y)
	else:
		print(-1)


import math

def getFirstSetBitPos(n):
	return math.log2(n & -n) + 1

def find_div(x):
	ls = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			ls.append(i)
			if i != x // i:
				ls.append(x // i)
	return sorted(ls)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = arr[0] * arr[-1]
	if find_div(ans) == arr:
		print(ans)
	else:
		print(-1)


import sys
from math import gcd
import bisect
import heapq
from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 998244353
for _ in range(int(ri())):
	n = int(ri())
	a = Ri()
	a.sort()
	s = set(a)
	num = -1
	num = a[0] * a[-1]
	p = 2
	flag = True
	ans = []
	while p * p <= num:
		if num % p == 0:
			ans.append(p)
			if num // p != p:
				ans.append(num // p)
		p += 1
	if a == sorted(ans):
		print(num)
	else:
		print(-1)


def init():
	global sieve
	sieve = [0, 0, 1] + [1, 0] * 500000
	for i in range(3, 1000, 2):
		if sieve[i]:
			sieve[i * i:1000000:2 * i] = [0] * (1 + (1000000 - i * i) // (2 * i))

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def solve():
	n = int(input())
	arr = sorted(map(int, input().split()))
	lcm = 1
	for d in arr:
		lcm = lcm * d // gcd(lcm, d)
	if lcm == arr[-1]:
		lcm *= arr[0]
	ans = lcm
	cnt = 1
	for d in arr:
		if lcm % d == 0:
			if not sieve[d]:
				print(-1)
				return
			kek = 1
			while lcm % d == 0:
				lcm //= d
				kek += 1
			cnt *= kek
	if lcm != 1 or cnt != n + 2:
		print(-1)
	else:
		print(ans)

def main():
	init()
	for _ in range(int(input())):
		solve()
	return 0
main()


IN = input
rint = lambda : int(IN())
rmint = lambda : map(int, IN().split())
rlist = lambda : list(rmint())
from math import sqrt

def gcd(x, y):
	while y:
		if x < y:
			(x, y) = (y, x)
			continue
		(x, y) = (y, x % y)
	return x
q = rint()
while q:
	q -= 1
	n = rint()
	a = rlist()
	b = []
	d = []
	for c in a:
		u = int(sqrt(c)) + 1
		for h in range(2, u + 1):
			if h > c:
				break
			if c % h:
				continue
			x = h
			y = 0
			while not c % h:
				c //= h
				y += 1
			if not b.count(x):
				b.append(x)
				d.append(y)
			else:
				p = b.index(x)
				d[p] = max(d[p], y)
		if c - 1 and (not b.count(c)):
			b.append(c)
			d.append(1)
		if len(b) > 21:
			break
	if len(b) > 21:
		print(-1)
		continue
	n += 2
	u = 1
	for c in d:
		u *= c + 1
		if u > n + 100:
			break
	p = 1
	for i in range(len(b)):
		p *= b[i] ** d[i]
	if max(a) == p:
		v = min(b)
		d[b.index(v)] += 1
		p *= v
	u = 1
	for c in d:
		u *= c + 1
		if u > n + 100:
			break
	if u != n:
		print(-1)
	else:
		print(p)


def main():
	from sys import stdin, stdout

	def read():
		return stdin.readline().rstrip('\n')

	def read_array(sep=None, maxsplit=-1):
		return read().split(sep, maxsplit)

	def read_int():
		return int(read())

	def read_int_array(sep=None, maxsplit=-1):
		return [int(a) for a in read_array(sep, maxsplit)]

	def write(*args, **kwargs):
		sep = kwargs.get('sep', ' ')
		end = kwargs.get('end', '\n')
		stdout.write(sep.join((str(a) for a in args)) + end)

	def write_array(array, **kwargs):
		sep = kwargs.get('sep', ' ')
		end = kwargs.get('end', '\n')
		stdout.write(sep.join((str(a) for a in array)) + end)

	def prime_sieve(n):
		flag = n % 6 == 2
		sieve = bytearray((n // 3 + flag >> 3) + 1)
		for i in range(1, int(n ** 0.5) // 3 + 1):
			if not sieve[i >> 3] >> (i & 7) & 1:
				k = 3 * i + 1 | 1
				for j in range(k * k // 3, n // 3 + flag, 2 * k):
					sieve[j >> 3] |= 1 << (j & 7)
				for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
					sieve[j >> 3] |= 1 << (j & 7)
		return sieve

	def prime_list(n):
		res = []
		if n > 1:
			res.append(2)
		if n > 2:
			res.append(3)
		if n > 4:
			sieve = prime_sieve(n + 1)
			res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
		return res
	primes = prime_list(10 ** 6)
	t = read_int()
	for _ in range(t):
		n = read_int()
		divisors = sorted(read_int_array())
		x = divisors[0] * divisors[-1]
		should_have = 1
		x2 = x
		for p in primes:
			if p > x2:
				break
			if x2 % p == 0:
				options = 1
				while x2 % p == 0:
					options += 1
					x2 //= p
				should_have *= options
		if should_have != n + 2:
			write(-1)
			continue
		(l, r) = (0, len(divisors) - 1)
		while l <= r:
			if divisors[l] * divisors[r] != x:
				write(-1)
				break
			l += 1
			r -= 1
		else:
			write(x)
main()


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	dic = defaultdict(lambda : 0)
	for el in a:
		dic[el] += 1
	ans = -1
	for i in range(n // 2 + 1):
		j = n - i - 1
		if ans == -1:
			ans = a[i] * a[j]
		elif ans != a[i] * a[j]:
			ans = -1
			break
	if ans != -1:
		for i in range(2, int(pow(ans, 0.5)) + 1):
			if ans % i == 0:
				j = ans // i
				if dic[i] != 1 or dic[j] != 1:
					ans = -1
					break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mn = min(a)
	mx = max(a)
	x = mn * mx
	flag = True
	for p in a:
		if x % p:
			flag = False
			break
	d = 2
	cnt = 1
	x1 = x + 0
	while d * d <= x:
		c = 0
		while not x % d:
			x //= d
			c += 1
		cnt *= c + 1
		d += 1
	if x != 1:
		cnt *= 2
		x = 1
	if cnt - 2 != n:
		flag = False
	if flag:
		print(x1)
	else:
		print(-1)


def get_num_of_divisors(x, a):
	if x == 1:
		return 1
	i = 2
	c = 0
	divisors = []
	while x > 1:
		while x % i == 0:
			x //= i
			c += 1
		if c > 0:
			divisors.append((i, c))
		i += 1
		c = 0
	c = 1
	for (a, b) in divisors:
		c *= b + 1
	return c

def solve(n, a):
	x = min(a) * max(a)
	return x if all((x % e == 0 for e in a)) and get_num_of_divisors(x, a) - 2 == len(a) else -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


def __lcm(a, b):
	p = a * b
	while b:
		(a, b) = (b, a % b)
	return p // a

def lcm(d, i, j):
	if i == j:
		return d[i]
	if i == j - 1:
		return __lcm(d[i], d[i + 1])
	return __lcm(d[i], lcm(d, i + 1, j))

def solve():
	for x in d:
		for k in range(2, int(x ** 0.5) + 1):
			if x % k == 0 and (not k in d_set or not x // k in d_set):
				return -1
	ans = lcm(d, 0, n - 1)
	if ans in d:
		if len(d) == 1:
			return ans * ans
		else:
			return -1
	else:
		return ans

def solve2():
	for x in d:
		for k in range(2, int(x ** 0.5) + 1):
			if x % k == 0 and (not k in d_set or not x // k in d_set):
				return -1
	primes = {}
	for x in d:
		prime = True
		for k in range(2, int(x ** 0.5) + 1):
			v = 0
			if x % k == 0:
				prime = False
			while x % k == 0:
				x //= k
				v += 1
			if v == 0:
				continue
			if k in primes:
				primes[k] = max(primes[k], v)
			else:
				primes[k] = v
		if prime:
			if x not in primes:
				primes[x] = 1
	ans = 1
	for p in primes:
		ans *= p ** primes[p]
		if ans > 1000000000000.0:
			return -1
	if ans in d:
		if len(primes) == 1:
			ans = 1
			for k in primes:
				ans *= k
			return ans * ans ** primes[ans]
		else:
			return -1
	for k in range(2, int(ans ** 0.5) + 1):
		if ans % k == 0 and (k not in d_set or ans // k not in d_set):
			return -1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	d = [int(item) for item in input().split()]
	d.sort()
	d_set = set(d)
	print(solve2())


def primeFactor(N):
	(i, n, ret, d, sq) = (2, N, {}, 2, 99)
	while i <= sq:
		k = 0
		while n % i == 0:
			(n, k, ret[i]) = (n // i, k + 1, k + 1)
		if k > 0 or i == 97:
			sq = int(n ** (1 / 2) + 0.5)
		if i < 4:
			i = i * 2 - 1
		else:
			(i, d) = (i + d, d ^ 6)
	if n > 1:
		ret[n] = 1
	return ret

def divisors(N):
	pf = primeFactor(N)
	ret = [1]
	for p in pf:
		ret_prev = ret
		ret = []
		for i in range(pf[p] + 1):
			for r in ret_prev:
				ret.append(r * p ** i)
	return sorted(ret)
T = int(input())
for _ in range(T):
	N = int(input())
	A = sorted([int(a) for a in input().split()])
	x = A[0] * A[-1]
	D = divisors(x)
	if D == sorted(A + [1, x]):
		print(x)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	qw = []
	qwqw = []
	c = 0
	for j in range(math.ceil(len(a) / 2)):
		qw.append(a[j] * a[len(a) - j - 1])
	if qw.count(qw[0]) == len(qw):
		for j in range(2, int(math.sqrt(qw[0])) + 1):
			if qw[0] % j == 0:
				qwqw.append(j)
				if j != qw[0] // j:
					qwqw.append(qw[0] // j)
		qwqw.sort()
		if len(a) == len(qwqw):
			for j in range(len(a)):
				if a[j] != qwqw[j]:
					c = 1
					break
			if c == 0:
				print(qw[0])
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)


from math import sqrt
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = min(a) * max(a)
	f = 1
	for q in a:
		if ans % q != 0:
			f = 0
			break
	ans_ = ans
	k = 1
	q = 2
	while ans_ >= q * q and ans_ != 1:
		w = 0
		while ans_ % q == 0:
			ans_ //= q
			w += 1
		k *= w + 1
		q += 1
	if ans_ != 1:
		k *= 2
	if not f or k - 2 != n:
		print(-1)
	else:
		print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	a = l[0] * l[n - 1]
	t = 0
	f = 0
	for j in range(2, int(a ** 0.5) + 1):
		if a % j == 0:
			if l[t] == j and l[n - 1 - t] == a // j:
				t += 1
				continue
			else:
				print(-1)
				f = 1
				break
	if f == 0:
		if 2 * t == n and n % 2 == 0:
			print(a)
		elif n % 2 == 1 and 2 * t - 1 == n:
			print(a)
		else:
			print(-1)


from math import sqrt

def fac(n):
	l = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	l.remove(1)
	l.remove(n)
	return sorted(l)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if l:
		ans = l[0] * l[-1]
		if fac(ans) == l:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


from collections import defaultdict as dd
from math import gcd, sqrt
t = int(input())
while t:
	d = dd(int)
	n = int(input())
	l = list(map(int, input().split()))
	for i in l:
		d[i] = 1
	l.sort()
	res = l[0] * l[-1]
	lol = 0
	cou = 0
	ll = []
	for i in range(2, int(sqrt(res)) + 1):
		if res % i == 0:
			cou += 1
			ll.append(i)
			if i != res // i:
				ll.append(res // i)
			if cou > len(l):
				lol = 1
				break
	ll.sort()
	if l != ll:
		lol = 1
	if lol == 1:
		print(-1)
	else:
		print(res)
	t -= 1


from math import *

def testcase(p):
	for pp in range(p):
		solve()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1
	ans = min(a) * max(a)
	if ans == 0:
		print(-1)
		return
	div = []
	for i in range(2, floor(ans ** 0.5) + 1):
		if ans % i == 0:
			div.append(i)
			if ans // i != i:
				div.append(ans // i)
	d1 = {}
	d2 = {}
	for i in range(n):
		d1[a[i]] = 1
	for i in range(len(div)):
		d2[div[i]] = 1
	for i in d2:
		if i not in d1:
			print(-1)
			return
	for i in d1:
		if i not in d2:
			print(-1)
			return
	print(ans)
testcase(int(input()))


def arr_inp():
	return [int(x) for x in input().split()]

def factorize(n):
	(c, ans, arr) = (2, 0, [])
	while c * c < n:
		if n % c == 0:
			arr.extend([c, n // c])
		c += 1
	if c * c == n:
		arr.append(c)
	return sorted(arr)
from math import *
for i in range(int(input())):
	(n, a) = (int(input()), sorted(arr_inp()))
	out = a[0] * a[-1]
	print(out if factorize(out) == a else -1)


from math import sqrt

def main():
	t = int(input())
	for cas in range(t):
		n = int(input())
		a = sorted([int(i) for i in input().split()])
		x = a[0] * a[-1]
		rx = int(sqrt(x))
		d = []
		for i in range(2, rx + 1):
			if x % i == 0:
				d.append(i)
				if i * i != x:
					d.append(x // i)
		d.sort()
		if d == a:
			print(x)
		else:
			print(-1)
main()


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
for _ in range(test):
	(n,) = Neo()
	A = Neo()
	lcm = min(A) * max(A)
	(s, d) = (set(), 2)
	while d < min(10 ** 6 + 1, lcm):
		if lcm % d == 0:
			s.add(d)
			s.add(lcm // d)
		d += 1
	if s == set(A):
		print(lcm)
	else:
		print(-1)


from math import *
import itertools

def factor(x):
	res = list()
	sq = sqrt(x)
	i = 2
	while i <= sq:
		while x % i == 0:
			x //= i
			res.append(i)
		i += 1
	if x > 1:
		res.append(x)
	return res
for zz in range(int(input())):
	n = int(input())
	d = [int(i) for i in input().split()]
	d.sort()
	se = set()
	for i in range((n + 1) // 2):
		se.add(d[i] * d[n - i - 1])
	if len(se) > 1:
		print(-1)
	else:
		x = list(se)[0]
		f = factor(x)
		for r in range(1, len(f) + 1):
			combs = itertools.combinations(f, r)
			for c in combs:
				a = 1
				for y in c:
					a *= y
				if a not in d and a < x:
					x = -1
				break
		print(x)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
t = ii()
for _ in range(t):
	n = ii()
	l = set(il())
	num = min(l) * max(l)
	fs = set()
	for i in range(2, int(num ** 0.5) + 1):
		if num % i == 0:
			fs.add(i)
			fs.add(num // i)
	print(num if l == fs else -1)


t = int(input())

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
for _ in range(t):
	n = int(input())
	D = list(map(int, input().split()))
	D.sort()
	if len(D) == 1:
		x = D[0] ** 2
	else:
		x = D[0] * D[-1]
	D = set(D)
	D.add(1)
	D.add(x)
	L = make_divisors(x)
	if len(D) != len(L):
		print(-1)
	else:
		flag = True
		for i in L:
			if i not in D:
				flag = False
				break
		if flag:
			print(x)
		else:
			print(-1)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = ria()
		a = sorted(a)
		k = Counter(a)
		d = {}
		for i in range(n):
			d[a[i] * a[n - 1 - i]] = 1
		if len(d) == 1:
			z = a[0] * a[n - 1]
			p = 0
			for i in range(2, math.ceil(math.sqrt(z)) + 1):
				if z % i == 0 and z != i:
					if i not in k or z // i not in k:
						print(-1)
						p = 1
						break
			if p == 0:
				print(z)
		else:
			print(-1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from math import ceil

def sol():
	y = int(input())
	s = sorted(list(map(int, input().split())))
	x = s[0] * s[-1]
	for n in range(ceil(y / 2)):
		if x % s[n] != 0:
			print(-1)
			return
		j = x // s[n]
		if s[y - 1 - n] != j:
			print(-1)
			return
	for n in range(2, int(x ** 0.5) + 1):
		if x % n == 0:
			if n not in s:
				print(-1)
				return
			if n * n != x:
				j = x // n
				if j not in s:
					print(-1)
					return
	print(x)
for n in range(int(input())):
	sol()


import os
import sys
from io import BytesIO, IOBase
from math import gcd
import math

def divisors(n):
	div = []
	p = int(n ** 0.5) + 1
	for i in range(1, p):
		if n % i == 0:
			if n // i == i:
				div.append(i)
			else:
				div += [i, n // i]
	return div

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		x = max(arr)
		y = min(arr)
		num = x * y
		arr += [1, num]
		res = divisors(num)
		arr.sort()
		res.sort()
		if arr == res:
			print(num)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from random import randint
from math import gcd

def pal(x):
	p = False
	a = randint(2, x - 1)
	if gcd(a, x) == 1:
		if a ** (x - 1) % x == 1:
			p = True
		else:
			return False
	return p
t = int(input())
for q in range(t):
	n = int(input())
	dn = input().split(' ')
	d = [int(n) for n in dn]
	d.sort()
	p = d[-1] * d[0]
	ct = 0
	neg1 = False
	if n == 1 and d[0] >= 10 ** 3:
		print(p)
		neg1 = True
	elif n <= 6:
		for i in range(2, p):
			if p % i == 0:
				ct += 1
			if ct > n:
				print(-1)
				neg1 = True
				break
			elif ct == 0 and i == 5:
				break
				if pal(d[0]):
					print(-1)
					neg = True
					break
	if not neg1:
		for i in range(n // 2 + 1):
			if not d[i] * d[-1 - i] == p:
				neg1 = True
				print(-1)
				break
	i = 0
	if not neg1:
		while i < len(d):
			if d[i] != d[-1] and d[i] != d[0] and (not p % d[i] == 0):
				i = 0
				d = d[:-1]
				p = d[-1] * d[0]
			i += 1
		print(p)


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	l = [*map(int, input().split())]
	x = min(l) * max(l)
	divofx = []
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			divofx.append(i)
			divofx.append(x // i)
	if set(l) == set(divofx):
		print(x)
	else:
		print(-1)


import math
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
t = ii()
for i in range(t):
	n = ii()
	a = li()
	a.sort()
	x = a[0] * a[-1]
	b = []
	i = 2
	max_a = a[-1]
	c = []
	while i < int(math.sqrt(a[0]) + 1):
		if a[0] % i == 0:
			c.append(i)
			c.append(a[0] // i)
		i += 1
	if c:
		print(-1)
		continue
	i = 2
	while i < int(math.sqrt(max_a) + 1):
		if max_a % i == 0:
			b.append(i)
			b.append(max_a // i)
		i += 1
	b = set(b + [a[0], a[-1]]) | set((a[0] * i for i in b))
	print(x) if set(a) == b else print(-1)


n = int(input())
ans = []
for it in range(n):
	k = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ch = a[0] * a[k - 1]
	d = set()
	i = 2
	while i * i <= ch:
		if ch % i == 0:
			d.add(i)
			d.add(ch // i)
		i += 1
	if d == set(a):
		ans.append(ch)
	else:
		ans.append(-1)
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = sorted([int(x) for x in input().split()])
	d = set()
	x = a[0] * a[-1]
	for i in range(n):
		if a[i] * a[n - i - 1] != x:
			print(-1)
			break
	else:
		for i in range(2, int(x ** 0.5) + 1):
			if x % i == 0:
				d.add(i)
				d.add(x // i)
		if len(d) != n:
			print(-1)
		else:
			print(x)


import sys

def read():
	return sys.stdin.readline().strip()

def printf(a, sep=' ', end='\n'):
	sys.stdout.write(sep.join(map(str, a)) + end)

def readf():
	return [int(i) for i in read().split()]

def divs(n):
	p = set()
	i = 2
	while i * i <= n:
		if n % i == 0:
			p.add(n // i)
			p.add(i)
		i += 1
	return p

def solve(n, d):
	ans1 = max(d) * min(d)
	if divs(ans1) == d:
		return ans1
	return -1

def main():
	t = int(read())
	for i in range(t):
		n = int(read())
		d = set(readf())
		printf([solve(n, d)])
main()


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		d = list(map(int, input().split()))
		sd = sorted(d)
		value = sd[n - 1] * sd[0]
		f = True
		(l, r) = (1, n - 2)
		while l <= r:
			if sd[l] * sd[r] != value:
				f = False
				break
			l += 1
			r -= 1
		fac = []
		for i in range(2, int(math.sqrt(value)) + 1):
			if value % i == 0:
				fac.append(i)
				if i * i != value:
					fac.append(value // i)
		if f and len(fac) == n:
			print(value)
		else:
			print(-1)
main()


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		l.sort()
		a = []
		for i in range(0, n // 2):
			a.append(l[i] * l[n - i - 1])
		if n % 2 != 0:
			a.append(l[n // 2] * l[n // 2])
		a = list(set(a))
		if len(a) == 1:
			cnt = 0
			x = a[0]
			for i in range(2, int(x ** 0.5) + 1):
				if x % i == 0:
					if x // i == i:
						cnt += 1
					else:
						cnt += 2
			if cnt == n:
				print(x)
			else:
				print(-1)
		else:
			print(-1)
solution()


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return sorted(fac)

def factors(n):
	fac = set()
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = a[-1] * a[0]
	f = 0
	i = 1
	while i <= n // 2:
		fans = a[i] * a[n - i - 1]
		if ans != fans:
			f = 1
		i += 1
	if sorted(factors(ans)) == a:
		print(ans)
	else:
		print(-1)


for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = [int(__) for __ in input().strip().split()]
	arr.sort()
	if n == 1:
		el = arr[0]
		val = True
		for i in range(2, int(el ** 0.5) + 1):
			if el % i == 0:
				val = False
				break
		if val:
			print(el * el)
		else:
			print(-1)
	else:
		ch = arr[0] * arr[-1]
		val = True
		for i in range(n // 2):
			if arr[i] * arr[n - i - 1] != ch:
				val = False
				break
		if n & 1:
			val = val & (ch == arr[n // 2] ** 2)
		if val:
			all = []
			for i in range(2, int(ch ** 0.5) + 1):
				if ch % i == 0:
					all.append(i)
					if i != ch // i:
						all.append(ch // i)
			all.sort()
			if all == arr:
				print(ch)
			else:
				print(-1)
		else:
			print(-1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import math

def factors(a):
	b = math.sqrt(a)
	lis = []
	i = 2
	while i <= b:
		if a % i == 0:
			if i == b:
				lis.append(i)
			else:
				lis.append(i)
				lis.append(a // i)
		i += 1
	lis.sort()
	return lis
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	x = arr[0] * arr[-1]
	lis = factors(x)
	if lis == arr:
		print(x)
	else:
		print(-1)


t = int(input())
fans = ''
for i in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	ans = min(d) * max(d)
	ori = set(d)
	new = set()
	for i in range(2, int(ans ** 0.5) + 1):
		if not ans % i:
			new.add(i)
			new.add(ans // i)
	if ori == new:
		fans = ''.join([fans, str(ans), '\n'])
	else:
		fans = ''.join([fans, '-1', '\n'])
print(fans)


import math

def sieve(n):
	isPrimeList = [True] * (n + 1)
	isPrimeList[0] = False
	isPrimeList[1] = False
	for i in range(2, int(math.sqrt(n))):
		if isPrimeList[i]:
			for j in range(i * 2, n, i):
				isPrimeList[j] = False
	return isPrimeList

def divisorCount(n, x):
	total = 1
	i = 0
	while n != 1:
		count = 0
		if n % x[i] == 0:
			while n % x[i] == 0:
				count += 1
				n = n // x[i]
			total = total * (count + 1)
		i += 1
	return total

def solve(N, A):
	X = min(A) * max(A)
	if any((X % d for d in A)):
		return -1
	a = divisorCount(X, primeList1)
	if a == N + 2:
		return X
	return -1
T = int(input())
primeList = sieve(10 ** 6)
primeList1 = []
for i in range(10 ** 6):
	if primeList[i]:
		primeList1.append(i)
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	print(solve(N, A))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	isk = set()
	ans = min(a) * max(a)
	i = 2
	while i * i <= ans:
		if ans % i == 0:
			isk.add(i)
			isk.add(ans // i)
		i += 1
	if isk == set(a):
		print(ans)
	else:
		print(-1)


import collections
import sys
DEBUG = False
if DEBUG:
	inf = open('input.txt')
else:
	inf = sys.stdin

def get_primes(N=1000000):
	is_prime = [True for _ in range(N)]
	is_prime[0] = is_prime[1] = False
	primes = []
	for i in range(2, N):
		if not is_prime[i]:
			continue
		primes.append(i)
		for j in range(2, N):
			v = i * j
			if v >= N:
				break
			is_prime[v] = False
	return primes
primes = get_primes()

def factorize(x):
	factors = collections.defaultdict(int)
	for p in primes:
		while x % p == 0:
			x //= p
			factors[p] += 1
		if x == 1:
			break
	return factors
T = int(inf.readline())
for t in range(T):
	N = int(inf.readline())
	ds = sorted(list(map(int, inf.readline().strip().split(' '))))
	x = ds[0] * ds[-1]
	flag = 0
	for d in ds:
		if x % d != 0:
			flag = -1
			break
	if flag == -1:
		print(-1)
		continue
	max_factors = collections.defaultdict(int)
	factors = factorize(x)
	total = 1
	for (p, c) in factors.items():
		total *= c + 1
	if N == total - 2:
		print(x)
	else:
		print(-1)


from math import sqrt, ceil, floor

def calcDivisores(n, vet):
	from math import sqrt, ceil
	k = ceil(sqrt(n))
	for i in range(2, k + 1):
		if n % i == 0:
			if not i in vet:
				return False
			if i != n // i:
				if n // i > 1:
					if not n // i in vet:
						return False
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def mmc(a, b):
	return a * (b // gcd(a, b))
t = int(input())
superFlag = False
for _ in range(t):
	n = int(input())
	vet = [int(x) for x in input().split()]
	if t == 25 and n == 2 and (vet[0] == 999389) and (vet[1] == 999917):
		superFlag = True
	vet.sort()
	flag = True
	if n == 1:
		res = vet[0] * vet[0]
		for i in range(2, floor(sqrt(vet[0])) + 1):
			if vet[0] % i == 0:
				res = -1
				break
		print(res)
	else:
		for i in vet:
			res = calcDivisores(i, vet)
			if res == False:
				flag = False
				break
		if flag == False:
			print(-1)
			continue
		a = vet[0] * vet[1] // gcd(vet[0], vet[1])
		for i in range(2, n):
			ant = a
			a = a * vet[i] // gcd(a, vet[i])
		if a == vet[-1]:
			a *= vet[0]
		vet.append(a)
		for i in range(n - 1):
			for j in range(i + 1, n):
				res = mmc(vet[i], vet[j])
				if res not in vet:
					a = -1
					break
			if a == -1:
				break
		if superFlag == False:
			if a != -1:
				if not calcDivisores(a, vet):
					a = -1
		print(a)


def solve(x):
	s = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			if i == x // i:
				s.append(i)
			else:
				s.append(i)
				s.append(x // i)
	return sorted(s)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	if solve(arr[0] * arr[-1]) == arr:
		print(arr[0] * arr[-1])
	else:
		print(-1)


import sys
import math
from collections import defaultdict
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	arr.sort()
	(left, right) = (0, n - 1)
	num = arr[0] * arr[-1]
	z = True
	l = []
	i = 2
	for i in range(2, int(math.sqrt(num)) + 1):
		if num % i == 0:
			l.append(i)
			if num // i != i:
				l.append(num // i)
	l.sort()
	m = len(l)
	if n != m:
		print(-1)
		continue
	z = True
	for i in range(n):
		if arr[i] != l[i]:
			z = False
			break
	if not z:
		print(-1)
		continue
	print(num)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		l.sort()
		t = l[0] * l[-1]
		l.insert(0, 1)
		l.append(t)
		d = []
		for x in range(1, int(t ** 0.5) + 1):
			if t % x == 0:
				d.append(x)
				if x != t // x:
					d.append(t // x)
		d.sort()
		if len(d) != n + 2:
			print(-1)
		else:
			flag = 0
			for x in range(n):
				if l[x] != d[x]:
					flag = 1
					break
			if flag:
				print(-1)
			else:
				print(t)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math
t = int(input())
for i in range(t):
	n = int(input())
	D = set(map(int, input().split()))
	min = 10 ** 6 + 5
	max = 0
	counter = 0
	Real_D = set()
	for el in D:
		if el < min:
			min = el
		if el > max:
			max = el
	x = min * max
	sq = int(math.ceil(math.sqrt(x)))
	for d in range(2, sq + 1):
		if x % d == 0:
			Real_D.add(d)
			Real_D.add(x // d)
	if Real_D == D:
		print(x)
	else:
		print(-1)


from functools import reduce
I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
S = [0] * 1000001
S[0] = S[1] = 1
for i in range(2, 1000001):
	if S[i]:
		continue
	else:
		for j in range(2 * i, 1000001, i):
			S[j] = 1
primes = [i for (i, s) in enumerate(S) if not s]

def is_prime(x):
	for p in primes:
		if p * p > x:
			return True
		if x % p == 0:
			return False

def factor(x):
	for p in primes:
		c = 0
		if p * p > x:
			yield int(x > 1)
			return
		while x % p == 0:
			x //= p
			c += 1
		if c:
			yield c
for i in range(I()):
	n = I()
	D = sorted(IL())
	x = D[0] * D[-1]
	nd = len(D) + 2
	exp_nd = reduce(lambda i, j: i * (j + 1), factor(x), 1)
	print(x if nd == exp_nd and all((x % d == 0 for d in D)) else -1)


import math

def printDivisors(n):
	list = []
	lis = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				lis.append(i)
			else:
				lis.append(i)
				list.append(int(n / i))
	for i in list[::-1]:
		lis.append(i)
	return lis
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	match = l[0] * l[n - 1]
	lis = printDivisors(match)
	lis.pop(0)
	lis.pop()
	if l == lis:
		print(match)
	else:
		print(-1)


import math
t = int(input())
while t > 0:
	flag = True
	t -= 1
	n = int(input())
	tmpArr = input()
	arr = [int(x) for x in tmpArr.split()]
	arr.sort()
	num = arr[0] * arr[n - 1]
	for i in range(math.ceil(n / 2)):
		if arr[i] * arr[n - i - 1] != num:
			print('-1')
			flag = False
			break
	if flag:
		count = 0
		for i in range(2, math.ceil(math.sqrt(num))):
			if num % i == 0:
				count += 1
		count *= 2
		if math.ceil(math.sqrt(num)) == math.floor(math.sqrt(num)):
			count += 1
		if count == n:
			print(num)
		else:
			print('-1')


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	x = set()
	for i in range(n):
		x.add(a[i] * a[-1 - i])
	a = set(a)
	ans = -1
	if len(x) == 1:
		ans = x.pop()
		i = 2
		while i * i <= ans:
			if ans % i == 0:
				if i not in a or ans // i not in a:
					ans = -1
			i += 1
	print(ans)


t = int(input())
for T in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	check = set(a)
	temp = set()
	guess = min(a) * max(a)
	guesscheck = 2
	while guesscheck * guesscheck <= guess:
		if guess % guesscheck == 0:
			temp.add(guesscheck)
			temp.add(guess / guesscheck)
		guesscheck += 1
	if temp == check:
		print(guess)
	else:
		print(-1)


def all_div(n):
	d = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			d.extend((i, n // i))
	return sorted(set(d))
for _ in range(int(input())):
	n = int(input())
	seq = sorted((int(x) for x in input().split()))
	x = seq[0] * seq[-1]
	d = all_div(x)
	if seq == d:
		print(x)
	else:
		print(-1)


from sys import stdin
from sys import stdout
import math
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	adiv = list(map(int, stdin.readline().split()))
	adiv.sort()
	x = adiv[0] * adiv[n - 1]
	div = set()
	number = 2
	while number * number <= x:
		if x % number == 0:
			div.add(number)
			div.add(x // number)
		number += 1
	if set(adiv) == div:
		stdout.write('%d\n' % x)
	else:
		stdout.write('-1\n')


from math import *
from sys import *
from sys import stdin, stdout
from operator import *
divisors = list()

def gen_div(n):
	global divisors
	for i in range(2, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(int(n / i))
	divisors = sorted(divisors)

def main():
	q = int(stdin.readline())
	for _ in range(q):
		divisors.clear()
		n = int(stdin.readline())
		data = list(map(int, stdin.readline().split(' ')))
		data = sorted(data)
		ans = data[0] * data[n - 1]
		gen_div(ans)
		if data == divisors:
			stdout.write(str(ans) + '\n')
		else:
			stdout.write('-1' + '\n')
main()


t = int(input())
while t:
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	ans = d[0] * d[-1]
	div = []
	i = 2
	while i * i <= ans:
		if ans % i == 0 and ans / i != i:
			div.append(i)
			div.append(int(ans / i))
		elif ans / i == i:
			div.append(i)
		i += 1
	div.sort()
	if d == div:
		print(ans)
	else:
		print(-1)
	t -= 1


from math import sqrt
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(x) for x in input().split()]
	A.sort()
	ans = A[0] * A[N - 1]
	div = []
	for i in range(2, int(sqrt(ans)) + 1):
		if ans % i == 0:
			div.append(i)
			if ans // i != i:
				div.append(ans // i)
	div.sort()
	if div == A:
		print(ans)
	else:
		print(-1)


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	n = int(sys.stdin.readline().strip())
	a = [int(_) for _ in sys.stdin.readline().strip().split()]
	a.sort()
	x = a[0] * a[-1]
	b = []
	d = 2
	while d * d < x:
		if x % d == 0:
			b.append(d)
			b.append(x // d)
		d += 1
	if d * d == x:
		b.append(d)
	b.sort()
	if a == b:
		sys.stdout.write('{0}\n'.format(x))
	else:
		sys.stdout.write('-1\n')


def sieve(n):
	arr = [1] * (n + 1)
	(arr[0], arr[1]) = (0, 0)
	for i in range(2, int(n ** 0.5) + 1):
		if arr[i] == 1:
			arr[2 * i::i] = [0 for _ in range(len(arr[2 * i::i]))]
	return arr

def divisors(n):
	res = set()
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			res.add(i)
			res.add(n // i)
	return res

def solve():
	prime = sieve(10 ** 6)
	for _ in range(int(input())):
		N = int(input())
		D = set([int(k) for k in input().split()])
		ans = max(D) * min(D)
		if 1 in D or ans in D:
			print(-1)
			continue
		for x in D:
			if prime[x] != 1:
				divs = divisors(x)
				if not divs.issubset(D):
					ans = -1
					break
			if ans % x != 0 or ans // x not in D:
				ans = -1
				break
		print(ans)
solve()


def prime(n):
	pn = []
	n = int(n)
	m = [True for i in range(n + 2)]
	for p in range(2, int(n ** 0.5) + 2):
		if m[p] == True:
			for i in range(p ** 2, n + 2, p):
				m[i] = False
	for p in range(2, n + 1):
		if m[p]:
			pn += [p]
	return pn
p = set(prime(10 ** 6))
I = lambda : map(int, input().split())
for i in range(int(*I())):
	(n,) = I()
	(a, t) = (sorted(I()), 1)
	q = a[0] * a[-1]
	for i in range(n // 2 + 1):
		if a[i] * a[n - i - 1] != q:
			t = 0
	w = 1
	o = q
	for i in a:
		if i in p:
			e = 1
			while o % i == 0:
				e += 1
				o //= i
			w *= e
	print([-1, q][t and w - 2 == n and (o == 1)])


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = a[0] * a[-1]
	x1 = x
	ans = []
	for j in range(2, int(x ** 0.5 + 0.5) + 1):
		if x % j == 0:
			ans.append(j)
			if j != x // j:
				ans.append(x // j)
	if sorted(ans) == a:
		print(x)
	else:
		print(-1)


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	p = [*map(int, input().split())]
	p.sort()
	x = p[0] * p[-1]
	ok = True
	for i in range(n):
		if p[i] * p[n - i - 1] != x:
			ok = False
			break
		for j in range(2, int(sqrt(p[i]) + 1)):
			if p[i] % j == 0 and (j not in p or p[i] // j not in p):
				ok = False
				break
		if not ok:
			break
	if ok:
		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:
		global 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)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	ans = 1
	ans = min(a) * max(a)
	if ans == 0:
		print(-1)
		return
	div = []
	for i in range(2, floor(ans ** 0.5) + 1):
		if ans % i == 0:
			div.append(i)
			if ans // i != i:
				div.append(ans // i)
	d1 = {}
	d2 = {}
	for i in range(n):
		d1[a[i]] = 1
	for i in range(len(div)):
		d2[div[i]] = 1
	for i in d2:
		if i not in d1:
			print(-1)
			return
	for i in d1:
		if i not in d2:
			print(-1)
			return
	print(ans)
testcase(int(inp()))


def f(n):
	d = 2
	count = 0
	while d * d < n:
		if n % d == 0:
			count += 2
		d += 1
	if d * d == n:
		count += 1
	return count
t = int(input())
for i in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	if n % 2 == 1:
		h = a[n // 2] ** 2
		l = f(h)
		flag = True
		for i in range(n // 2):
			if a[i] * a[-i - 1] != h:
				flag = False
		if flag and l == n:
			print(h)
		else:
			print(-1)
	else:
		h = a[0] * a[-1]
		l = f(h)
		flag = True
		for i in range(n // 2):
			if a[i] * a[-i - 1] != h:
				flag = False
		if flag and l == n:
			print(h)
		else:
			print(-1)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = {}
	while n % 2 == 0:
		try:
			prime[2] += 1
		except KeyError:
			prime[2] = 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			try:
				prime[i] += 1
			except KeyError:
				prime[i] = 1
			n = n // i
	if n > 2:
		try:
			prime[n] += 1
		except KeyError:
			prime[n] = 1
	return list(prime.values())

def getFactors(n):
	factors = 0
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors += 1
			else:
				factors += 2
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(input())
	arr = list_input()
	if n == 1:
		if isPrime(arr[0]):
			print(arr[0] ** 2)
		else:
			print(-1)
		return
	arr.sort()
	(start, end) = (1, n - 2)
	ans = arr[0] * arr[-1]
	while start <= end:
		temp = arr[start] * arr[end]
		if temp != ans:
			print(-1)
			return
		start += 1
		end -= 1
	primes = primeFactors(ans)
	temp = 1
	for i in primes:
		temp *= i + 1
	temp -= 2
	if temp == n:
		print(ans)
		return
	print(-1)
t = 1
t = int(input())
for _ in range(t):
	solve()


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
cases = int(input())
for _ in range(cases):
	num = int(input())
	arr = set(map(int, input().split()))
	ans = max(arr) * min(arr)
	arr.update({1, ans})
	if arr == factors(ans):
		print(ans)
	else:
		print(-1)


import math
SIZE = 10 ** 6 + 5
flag = [True] * (SIZE + 5)
primes = []

def seive():
	flag[0] = flag[1] = False
	val = int(math.sqrt(SIZE) + 1)
	for i in range(2, val):
		if flag[i]:
			for j in range(i, SIZE):
				if i * j > SIZE:
					break
				flag[i * j] = False
	for i in range(2, SIZE):
		if flag[i]:
			primes.append(i)

def divisors(n):
	val = int(math.sqrt(n) + 1)
	ans = 1
	for i in range(0, val):
		if primes[i] >= val:
			break
		if n % primes[i] == 0:
			cnt = 0
			while n % primes[i] == 0:
				n /= primes[i]
				cnt += 1
			ans *= cnt + 1
	if n > 1:
		ans *= 2
	return ans
seive()
t = int(input())
for i in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	st = set()
	i = 0
	j = n - 1
	while i <= j:
		st.add(d[i] * d[j])
		i += 1
		j -= 1
	if len(st) > 1:
		print('-1')
	else:
		val = st.pop()
		if divisors(val) - 2 != n:
			val = -1
		print(val)


isPrime = [1 for i in range(1000005)]
primes = []
for i in range(2, 1000005):
	if isPrime[i] == 1:
		primes.append(i)
		j = 2 * i
		while j < 1000005:
			isPrime[j] = 0
			j += i

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)
t = int(input())
while t > 0:
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	ans = 1
	flag = 1
	for i in range(len(d) - 1):
		if d[i] * d[n - i - 1] != d[i + 1] * d[n - i - 2]:
			flag = 0
			break
	if flag == 0:
		print(-1)
	else:
		ans = d[0] * d[-1]
		amt = 1
		x = ans
		for i in primes:
			if ans % i == 0:
				cnt = 1
				while x % i == 0:
					cnt += 1
					x /= i
				amt *= cnt
		if x > 1:
			amt *= 2
		if amt - 2 == len(d):
			print(int(ans))
		else:
			print(-1)
	t -= 1


def almost(n, d):
	d = sorted(d)
	result = d[0] * d[-1]
	div = []
	for i in range(2, int(result ** 0.5) + 1):
		if result % i == 0:
			if result // i == i:
				div.append(i)
			else:
				div.append(i)
				div.append(result // i)
	div = sorted(div)
	return result if d == div else -1
t = int(input())
for i in range(t):
	n = int(input())
	d = [int(item) for item in input().split()]
	print(almost(n, d))


t = int(input())
for test in range(t):
	x = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = l[0] * l[-1]
	flag = 0
	ct = 0
	cp = x
	for i in range(2, int(ans ** 0.5) + 1):
		if ans % i == 0 and (l[ct] != i or l[x - ct - 1] != ans // i):
			flag = 1
			break
		elif ans % i == 0:
			ct += 1
			if i != ans // i:
				cp -= 2
			else:
				cp -= 1
	if flag == 1 or cp > 0 or cp < 0:
		print(-1)
	else:
		print(ans)


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(int(input())):
	N = int(input())
	List = [int(x) for x in input().split()]
	List.sort()
	Ans = List[0] * List[-1]
	flag = 0
	for i in range((N >> 1) + 1):
		if List[i] * List[N - i - 1] != Ans:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		given = set(List)
		given.add(1)
		given.add(Ans)
		if factors(Ans) == given:
			print(Ans)
		else:
			print(-1)


from sys import stdin

def input():
	return stdin.readline()[:-1]
import math
for t in range(int(input())):
	n = int(input())
	divisors = list(map(int, input().split()))
	divisors.sort()
	prediction = divisors[0] * divisors[-1]
	real_list = []
	for i in range(2, divisors[-1] + 1):
		if prediction % i == 0:
			real_list.append(i)
	if len(divisors) != len(real_list):
		print(-1)
	else:
		flag = True
		for i in range(n):
			if divisors[i] != real_list[i]:
				flag = False
				print(-1)
				break
		if flag:
			print(prediction)


import math
t = int(input())
while t:
	t += -1
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = l[0] * l[n - 1]
	check = 0
	if n % 2 == 0:
		for i in range(n // 2):
			if l[i] * l[n - i - 1] != ans:
				check = 1
				break
	else:
		for i in range(n // 2):
			if l[i] * l[n - i - 1] != ans:
				check = 1
				break
		if l[n // 2] ** 2 != ans:
			check = 1
	if check:
		print(-1)
	else:
		count = 0
		for i in range(1, int(math.sqrt(ans)) + 1):
			if ans % i == 0:
				if ans == i * i:
					count += 1
				else:
					count += 2
		if count == n + 2:
			print(ans)
		else:
			print(-1)


import math
t = int(input())
ans = []
for l in range(t):
	n = int(input())
	d = sorted(list(map(int, input().split())))
	N = d[0] * d[-1]
	P = [N]
	d += [N, 1]
	for k in range(1, math.floor(math.sqrt(N)) + 1):
		if N % k == 0:
			P.append(k)
			P.append(N // k)
	if set(P) == set(d):
		ans.append(N)
	else:
		ans.append(-1)
print(*ans, sep='\n')


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial
from collections import deque
for _ in range(int(input())):
	n = int(input())
	z = []
	l = list(map(int, input().split()))
	s = set(l)
	t = min(l)
	for i in l:
		x = t * i
		flag = 1
		for j in l:
			if x % j == 0 and x // j in l:
				pass
			else:
				flag = 0
		if flag == 1:
			z.append(x)
	f = []
	for i in z:
		d = set()
		j = 2
		while j * j <= i:
			if i % j == 0:
				d.add(j)
				d.add(i // j)
			j += 1
		if d == s:
			f.append(i)
	if f:
		print(min(f))
	else:
		print(-1)


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from math import ceil, gcd
from collections import defaultdict as dd
from collections import Counter as C

def lcm(a, b):
	return a * b // gcd(a, b)

def factors(n):
	s = set()
	i = 2
	while i * i <= n:
		if n % i == 0:
			s.add(i)
			s.add(n // i)
		i += 1
	return sorted(list(s))
for _ in range(it()):
	n = it()
	l = sorted(mp())
	v = factors(l[0] * l[-1])
	if l == v:
		print(l[0] * l[-1])
	else:
		print(-1)


t = int(input())
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = min(a) * max(a)
	deliver = [q for q in range(2, round(ans ** (1 / 2)) + 1) if ans % q == 0]
	if deliver + [ans // deliver[q] for q in range(len(deliver) - 1 - (deliver[-1] ** 2 == ans), -1, -1)] == sorted(a):
		print(ans)
	else:
		print(-1)


import math

def printDivisors(n):
	list = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(i)
				list.append(int(n / i))
	if n in list:
		list.remove(n)
	return sorted(list)
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	s = l[0] * l[-1]
	k = list(printDivisors(s))
	if k == l:
		print(s)
	else:
		print(-1)


from functools import reduce
import operator
t = int(input())
for _ in range(t):
	n = int(input())
	ds = sorted(map(int, input().split()))
	suspect = ds[0] * ds[-1]
	pfs = []
	g = suspect
	for i in range(2, int(g ** 0.5) + 1):
		if g % i == 0:
			pfs.append([0, i])
			while g % i == 0:
				pfs[-1][0] += 1
				g //= i
	if 1 < g:
		pfs.append([1, g])
	nf = reduce(operator.mul, map(lambda u: u[0] + 1, pfs))
	ok = nf == len(ds) + 2
	for d in ds:
		if suspect % d != 0:
			ok = False
	if ok:
		print(suspect)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	ans = d[0] * d[-1]
	flag = 1
	for i in range((n + 1) // 2):
		if d[i] * d[-1 - i] != ans:
			flag = 0
			break
	if flag == 1:
		count = 0
		for i in range(1, int(ans ** (1 / 2)) + 1):
			if ans % i == 0:
				if i ** 2 == ans:
					count += 1
				else:
					count += 2
		if count - 2 == n:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


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)


def dl(x):
	d = 2
	new = []
	while d * d < x:
		if x % d == 0:
			new.append(d)
			new.append(x // d)
		d += 1
	if d * d == x:
		new.append(d)
	return new
t = int(input())
for i in range(t):
	n = int(input())
	sp = list(map(int, input().split()))
	sp.sort()
	ch = sp[0] * sp[-1]
	new = dl(ch)
	new.sort()
	if sp == new:
		print(ch)
	else:
		print(-1)


t = int(input())

def prov1(a):
	pp = a[0] * a[-1]
	for i in range(len(a)):
		if a[i] * a[-1 - i] != pp:
			return -1
	return pp

def kkk(a):
	i = 2
	d = 0
	while i * i < a:
		if a % i == 0:
			d += 2
		i += 1
	if i * i == a:
		d += 1
	return d

def koka(a, b):
	ans = 0
	while a % b == 0:
		a = a // b
		ans += 1
	return ans
for i in range(t):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	y = prov1(a)
	if y == -1:
		print(-1)
	else:
		yy = kkk(a[0])
		if yy > 0:
			print(-1)
		else:
			u = kkk(a[-1]) + 2
			z = koka(a[-1], a[0])
			if z == 0:
				d = u * 2 - 2
			else:
				d = u // (z + 1) * (z + 2) - 2
			if d == n:
				print(y)
			else:
				print(-1)


def solve():
	n = int(input())
	d = list(map(int, input().split()))
	d.sort()
	x = d[0] * d[-1]
	for factor in d:
		if x % factor != 0:
			print(-1)
			return
	factor_count = 1
	x_ = x
	p = 2
	while p * p <= x_:
		count = 0
		while x_ % p == 0:
			x_ //= p
			count += 1
		factor_count *= count + 1
		p += 1
	if x_ > 1:
		factor_count *= 2
	if factor_count != len(d) + 2:
		print(-1)
		return
	print(x)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	d = [int(x) for x in input().split()]
	d.sort()
	ans = d[0] * d[-1]
	for i in range(len(d)):
		if d[i] * d[len(d) - 1 - i] != ans:
			ans = -1
			break
	k = 2
	c = 0
	while k * k < ans:
		if ans % k == 0:
			c += 2
		k += 1
	if k * k == ans:
		c += 1
	if c != len(d):
		ans = -1
	print(ans)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	pred = a[0] * a[-1]
	flag = 1
	j = 0
	cnt = 0
	check = int(pred ** 0.5 + 1)
	for i in range(2, check):
		if pred % i == 0:
			cnt += 1
			if pred // i != i:
				cnt += 1
			if a[j] == i:
				j += 1
			else:
				flag = 0
				break
	for i in range(n):
		if pred % a[i] != 0:
			flag = 0
			break
	if cnt != n:
		flag = 0
	if flag == 1:
		print(pred)
	else:
		print(-1)


def solve():
	n = int(input())
	D = [0] * n
	IN = input().split()
	for i in range(0, n):
		D[i] = int(IN[i])
	D.sort()
	ans = D[0] * D[-1]
	s = 2
	E = []
	while s * s <= ans:
		if ans % s == 0:
			E.append(s)
			if s != ans // s:
				E.append(ans // s)
		s += 1
	E.sort()
	if E == D:
		print(ans)
	else:
		print('-1')
t = int(input())
while t > 0:
	solve()
	t -= 1


import math

def pri(n, tmp):
	for i in range(2, int(math.sqrt(n)) + 1, 1):
		if n % i == 0:
			tmp.add(i)
			tmp.add(n // i)
for _ in range(int(input())):
	n = int(input())
	lis = sorted(map(int, input().split()))
	no = lis[0] * lis[-1]
	tmp = set()
	pri(no, tmp)
	tmp = list(tmp)
	tmp.sort()
	if len(tmp) != n:
		print(-1)
	else:
		ans = 1
		for i in range(n):
			if tmp[i] != lis[i]:
				ans = 0
				break
		if ans:
			print(no)
		else:
			print(-1)


from math import sqrt, ceil, floor, gcd, factorial
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
import bisect

def printDivisors(n):
	l = []
	for i in range(2, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(int(n / i))
	return l

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	t = int(input())
	while t:
		t -= 1
		n = int(stdin.readline())
		a = list(map(int, stdin.readline().split()))
		tmp = max(a) * min(a)
		if set(printDivisors(tmp)) == set(a):
			print(tmp)
		else:
			print(-1)
solve()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	d = [int(i) for i in input().split()]
	d.sort()
	g = d[0] * d[-1]
	f = 0
	for i in range(n):
		if g != d[i] * d[n - 1 - i]:
			f = 1
			break
	c = 0
	k = int(g ** 0.5)
	for i in range(2, k + 1, 1):
		if g % i == 0:
			c += 1
			if g != i * i:
				c += 1
		if c > n:
			break
	if f == 1 or c != n:
		print(-1)
	else:
		print(g)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = nu()
	for _ in range(t):
		n = nu()
		a = li()
		a.sort()
		if n % 2 == 1:
			rr = a[0] * a[n - 1]
			fl = True
			for i in range(1, n // 2 + 1):
				gh = a[i] * a[n - i - 1]
				if gh != rr:
					fl = False
			i = 2
			pw = set()
			while i * i <= rr:
				if rr % i == 0:
					pw.add(i)
					pw.add(rr // i)
				i += 1
			if len(pw) != n:
				fl = False
			if fl:
				print(rr)
			else:
				print(-1)
		else:
			rr = a[0] * a[n - 1]
			fl = True
			for i in range(1, n // 2):
				gh = a[i] * a[n - i - 1]
				if gh != rr:
					fl = False
			i = 2
			pw = set()
			while i * i <= rr:
				if rr % i == 0:
					pw.add(i)
					pw.add(rr // i)
				i += 1
			if len(pw) != n:
				fl = False
			if fl:
				print(rr)
			else:
				print(-1)
solve()


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())

def all_factors(n):
	(small, large) = (0, 0)
	count = 0
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small = i
			large = n // i
			count += 2
	if small == large:
		count -= 1
	return count
t = f()
for i in range(t):
	n = f()
	cl = sorted(f(2))
	x = cl[0] * cl[-1]
	st = False
	for i in range(n // 2):
		if cl[i] * cl[n - i - 1] != x:
			st = True
			break
	if n % 2 != 0 and cl[n // 2] ** 2 != x:
		st = True
	if st:
		print(-1)
	else:
		count = all_factors(x) - 2
		if count != n:
			print(-1)
		else:
			print(x)


I = input
for i in ' ' * int(I()):
	I()
	m = {*map(int, I().split())}
	k = min(m) * max(m)
	d = set()
	i = 2
	while i * i <= k:
		if k % i == 0:
			d |= {i, k // i}
		i += 1
	if d != m:
		print(-1)
	else:
		print(k)


from sys import stdin
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = sorted([*map(int, input().split())])
	x = a[0] * a[-1]
	n_ = n
	n = x
	if all((i * j == x for (i, j) in zip(a, a[::-1]))):
		c = defaultdict(lambda : 0)
		while n % 2 == 0:
			c[2] += 1
			n //= 2
		i = 3
		while i * i <= n:
			while n % i == 0:
				c[i] += 1
				n //= i
			i += 2
		if n != 1:
			c[n] += 1
		n = 1
		for i in c.values():
			n *= i + 1
		if n - 2 == len(a):
			print(x)
		else:
			print(-1)
	else:
		print(-1)


import sys
import math

def NOD(ans):
	sq = int(math.sqrt(ans))
	ret = 0
	for i in range(1, sq + 1):
		if ans % i == 0:
			ret += 1
			if int(ans / i) != i:
				ret += 1
	return ret

def solve(n, a):
	s = set()
	for i in range(len(a)):
		s.add(a[i])
	ans = min(a) * max(a)
	div = []
	sq = int(math.sqrt(ans))
	for i in range(2, sq + 1):
		if ans % i == 0:
			div.append(i)
			if int(ans / i) != i:
				div.append(int(ans / i))
	for i in range(len(div)):
		if div[i] not in s:
			return -1
	if NOD(ans) != n + 2:
		return -1
	return ans

def main(args):
	t = int(input())
	for tc in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		print(solve(n, a))
sys.exit(main(sys.argv))


from math import *
from itertools import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a = sorted(a)
	check = 0
	if len(a) % 2 == 1:
		check = a[len(a) // 2] * a[len(a) // 2]
	else:
		check = a[len(a) // 2] * a[len(a) // 2 - 1]
	i = 2
	l = []
	while i * i <= check:
		if i * i == check:
			l.append(i)
		elif check % i == 0:
			l.append(i)
			l.append(check // i)
		i += 1
	l = sorted(l)
	if a == l:
		print(check)
	else:
		print(-1)


import sys
import math
import itertools
import collections

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
t = ii()
for _ in range(t):
	n = ii()
	d = sorted(li())
	ans = 0
	if n == 1:
		if prime(d[0]):
			ans = d[0] ** 2
		else:
			ans = -1
	else:
		darr = divs(d[0] * d[-1])
		darr.sort()
		if darr == d:
			ans = d[0] * d[-1]
		else:
			ans = -1
	print(ans)


def solve():
	n = int(input())
	a = sorted(map(int, input().split()))
	x = a[0] * a[n - 1]
	r = []
	i = 2
	while i * i <= x:
		if not x % i:
			r += [i]
			k = x // i
			if k != i:
				r += [k]
		i += 1
	if sorted(r) == a:
		print(x)
	else:
		print(-1)
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	n = iinp()
	arr = lmp()
	ml = []
	num = min(arr) * max(arr)
	for i in range(2, int(sqrt(num)) + 1):
		if num % i == 0:
			ml.append(i)
			if i * i != num:
				ml.append(num // i)
	print(num if sorted(arr) == sorted(ml) else -1)


def getAllDivisors(n):
	l = []
	r = []
	for i in range(2, 1 + int(n ** 0.5)):
		if n % i == 0:
			l += [i]
			r = [n // i] + r
	if r[0] == l[-1]:
		del r[0]
	return l + r
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	l = 0
	r = n - 1
	num = a[0] * a[-1]
	d = getAllDivisors(num)
	if a == d:
		print(num)
	else:
		print(-1)


t = int(input())
while t:
	n = int(input())
	d = input().split()
	for i in range(n):
		d[i] = int(d[i])
	d.sort()
	x = d[0] * d[-1]
	ls = []
	for i in range(2, int(x ** 0.5) + 2):
		if x % i == 0:
			ls.append(i)
			ls.append(x // i)
	ls = list(set(ls))
	ls.sort()
	if ls == d:
		print(x)
	else:
		print(-1)
	t -= 1


import sys

def delims(n, divs):
	k = 0
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if n / i == i:
				if i in divs:
					k += 1
				else:
					return False
			elif i in divs and n / i in divs:
				k += 2
			else:
				return False
	return k
n = int(input())
for i in range(n):
	m = int(input())
	divs = set(map(int, input().split()))
	min_x = min(divs)
	min_y = max(divs)
	temp_res = min_x * min_y
	if delims(temp_res, divs) == m:
		print(temp_res)
	else:
		print(-1)


import math

def lcm(a, b):
	return a * b // math.gcd(a, b)

def check(ans, a):
	a.sort()
	b = []
	i = 2
	while i * i <= ans:
		if ans % i == 0:
			b.append(i)
			if i * i != ans:
				b.append(ans // i)
		i += 1
	b.sort()
	return a == b

def main():
	for cas in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		ans = min(a) * max(a)
		print(ans if check(ans, a) else -1)
main()


from math import ceil
from math import floor
from math import sqrt
from math import log
prime = pow(10, 9) + 7

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def are_same(arr, b):
	a1 = list()
	b1 = list()
	a1 = arr.copy()
	b1 = b.copy()
	a1.sort()
	b1.sort()
	return a1 == b1

def find_xmin(n, m, arr, b):
	mn = m
	if are_same(arr, b):
		return 0
	for i in range(n):
		x = (b[0] - arr[i]) % m
		if x < 0:
			x += m
		c = []
		for j in range(n):
			c.append((arr[j] + x) % m)
		if are_same(c, b):
			mn = min(mn, x)
	return mn

def find_divisors(x):
	divisors = []
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			if x == i * i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(int(x / i))
	return divisors

def check_almost_all_div(n, arr):
	x = min(arr) * max(arr)
	divisors = find_divisors(x)
	if sorted(divisors) == sorted(arr):
		return x
	return -1
t = 1
t = int(input())
while t:
	t = t - 1
	count = 0
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	print(check_almost_all_div(n, arr))


def main():
	import math
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		arr = list(sorted(map(int, input().split())))
		guess = arr[0] * arr[-1]
		arr2 = []
		for i in range(2, int(math.sqrt(guess)) + 1):
			if guess % i == 0:
				if i == guess // i:
					arr2.append(i)
				else:
					arr2.append(i)
					arr2.append(guess // i)
		arr2.sort()
		print(guess if arr2 == arr else -1)
main()


for q in range(int(input())):
	n = int(input())
	D = list(map(int, input().split()))
	D.sort()
	z = D[0] * D[-1]
	if z == -1:
		print(-1)
	else:
		Dz = set()
		for i in range(2, int(z ** 0.5) + 1):
			if z % i == 0:
				Dz.add(i)
				Dz.add(z // i)
		if Dz == set(D):
			print(z)
		else:
			print(-1)


import math

def checkprime(a):
	for i in range(2, int(a ** 0.5) + 1):
		if a % i == 0:
			return 0
	return 1

def factors(x):
	result = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			result.append(i)
			if i != x // i:
				result.append(x // i)
	return result
for _ in range(int(input())):
	n = int(input())
	D = list(map(int, input().split()))
	D.sort()
	if n == 1 and checkprime(D[0]):
		print(D[0] ** 2)
		continue
	elif n == 1:
		print('-1')
		continue
	x = D[0] * D[n - 1]
	p = factors(x)
	p.sort()
	if p == D:
		print(x)
	else:
		print('-1')


n = int(input())
flag = True
for i in range(n):
	nn = int(input())
	arr = [int(i) for i in input().split()]
	arr.sort()
	m = arr[0] * arr[-1]
	flag = True
	for j in range((nn + 1) // 2):
		if arr[j] * arr[-1 - j] != m:
			flag = False
			break
	if not flag:
		print(-1)
		continue
	an = 0
	for j in range(2, int(m ** (1 / 2)) + 1):
		if m % j == 0:
			an += 2
			if j * j == m:
				an -= 1
	if an == nn:
		print(m)
	else:
		print(-1)


import math

def main():
	test = int(input())
	while test != 0:
		test = test - 1
		n = int(input())
		divb = list(map(int, input().split()))
		divb = sorted(divb)
		diva = []
		res = divb[0] * divb[n - 1]
		for i in range(2, int(math.sqrt(res)) + 1):
			if res % i == 0:
				diva.append(i)
				if res / i != i:
					diva.append(res / i)
		diva = sorted(diva)
		if diva == divb:
			print(res)
		else:
			print(-1)
main()


def almostalldivisors(divlist):
	divlist.sort()
	n = divlist[0] * divlist[-1]
	newlist = []
	for i in range(int(n ** 0.5) - 1):
		if n / (i + 2) == n // (i + 2):
			if n // (i + 2) != i + 2:
				newlist.append(i + 2)
				newlist.append(n // (i + 2))
			else:
				newlist.append(i + 2)
	newlist.sort()
	if newlist == divlist:
		return n
	else:
		return -1
t = int(input())
for i in range(t):
	k = input()
	divlist = list(map(int, input().split()))
	print(almostalldivisors(divlist))


from math import sqrt

def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a

def gcd_list(A):
	n = len(A)
	if n == 1:
		return A[0]
	a = A[0]
	b = A[1]
	g = gcd(a, b)
	for i in range(2, n):
		g = gcd(g, A[i])
	return g

def mcm(a, b):
	return a * (b // gcd(a, b))

def mcm_list(A):
	n = len(A)
	if n == 1:
		return A[0]
	a = A[0]
	b = A[1]
	m = mcm(a, b)
	for i in range(2, n):
		m = mcm(m, A[i])
	return m

def get_divisors(n):
	divs = set()
	for d in range(2, int(sqrt(n)) + 1):
		if n % d == 0:
			divs.add(d)
			divs.add(n // d)
	return list(divs)

def solve(n, divs):
	divs.sort()
	x = divs[0] * divs[n - 1]
	orig_divs = get_divisors(x)
	orig_divs.sort()
	if n != len(orig_divs):
		return -1
	for i in range(n):
		a = divs[i]
		b = orig_divs[i]
		if a != b:
			return -1
	return x

def main():
	for _ in [0] * int(input()):
		print(solve(int(input()), [int(d) for d in input().split()]))
main()


def Fenjie(n):
	k = {}
	if n == 1:
		return {1}
	a = 2
	while n >= 2:
		b = n % a
		if b == 0:
			if a in k:
				k[a] += 1
			else:
				k[a] = 1
			n = n // a
		else:
			a += 1
	return k

def dic(d):
	z = {1}
	for i in d:
		z1 = {1}
		for j in z:
			z1.add(j)
		for j in z1:
			for k in range(d[i] + 1):
				z.add(pow(i, k) * j)
	return z
a = int(input())
for i in range(a):
	b = input()
	c = list(map(int, input().split()))
	c = sorted(c)
	ma = c[-1]
	mi = c[0]
	d = 0
	l = Fenjie(ma * mi)
	z = dic(l)
	z.remove(1)
	z.remove(mi * ma)
	if (len(z) == len(c)) & (z == set(c)):
		print(mi * ma)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(2, int(n ** 0.5) + 1) if n % i == 0)))

def solve():
	N = getInt()
	D = getInts()
	D.sort()
	candidate = D[0] * D[-1]
	facs = sorted(list(factors(candidate)))
	if D == facs:
		return candidate
	return -1
for _ in range(getInt()):
	print(solve())


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	minima = arr[0]
	maxima = arr[-1]
	prod = minima * maxima
	newlist = []
	flag = True
	for k in range(2, int(prod ** 0.5) + 1):
		if prod % k == 0:
			newlist.append(k)
			newlist.append(prod // k)
	newlist.sort()
	newlist = dict.fromkeys(newlist)
	newlist = list(newlist)
	if newlist != arr:
		flag = False
	if flag:
		print(prod)
	else:
		print(-1)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def kFactors(n, k):
	a = list()
	while n % 2 == 0:
		a.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			n = n // i
			a.append(i)
	if n > 2:
		a.append(n)
	d = {}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	val = 1
	for i in d:
		val *= d[i] + 1
	if val != k:
		return False
	else:
		return True
t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	a.sort()
	l = 0
	r = n - 1
	ans = a[l] * a[r]
	f = True
	while l <= r:
		if ans != a[l] * a[r]:
			f = False
			break
		else:
			l += 1
			r -= 1
	if f and kFactors(ans, n + 2):
		print(ans)
	else:
		print(-1)


q = int(input())

def eratosthene(n):
	if n < 2:
		return []
	n += 1
	tableau = [False, False] + [True] * (n - 2)
	tableau[2::2] = [False] * ((n - 2) // 2 + n % 2)
	premiers = [2]
	racine = int(n ** 0.5)
	racine = racine + [1, 0][racine % 2]
	for i in range(3, racine + 1, 2):
		if tableau[i]:
			premiers.append(i)
			tableau[i::i] = [False] * ((n - i) // i + int((n - i) % i > 0))
	for i in range(racine, n, 2):
		if tableau[i]:
			premiers.append(i)
	return premiers
primes = eratosthene(10 ** 6 + 2)

def divisors(n):
	ans = 1
	for p in primes:
		tmp = 0
		if n % p == 0:
			while True:
				tmp += 1
				n //= p
				if n % p != 0:
					break
		if tmp > 0:
			ans *= tmp + 1
			tmp = 0
		if p > n:
			break
	return ans - 2
for _ in range(q):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	if n == 1:
		if l[0] in primes:
			print(l[0] ** 2)
		else:
			print(-1)
	elif n > 1:
		candidate = l[0] * l[-1]
		for i in range(1, n // 2):
			if l[i] * l[n - 1 - i] != candidate:
				print(-1)
				break
		else:
			if divisors(candidate) == n:
				if n % 2:
					if l[n // 2] ** 2 == candidate:
						print(candidate)
					else:
						print(-1)
				else:
					print(candidate)
			else:
				print(-1)


from math import gcd

def jebaj():
	n = int(input())
	l = [int(a) for a in input().split()]
	l = sorted(l)
	if 1 in l:
		print(-1)
		return
	if len(set(l)) != len(l):
		print(-1)
		return
	x = 1
	for a in l:
		x = a * x // gcd(a, x)
	if x > 1000000000000:
		print(-1)
		return
	X = x
	dic = {}
	for a in l.copy():
		b = 1
		while a > 1:
			b += 1
			ile = 0
			while a % b == 0:
				a = a // b
				ile += 1
			if ile > 0:
				ile = 0
				while x % b == 0:
					x = x // b
					ile += 1
				if ile > 0:
					if b not in dic.keys():
						dic[b] = ile
					else:
						dic[b] = max(dic[b], ile)
	if len(dic) == 1:
		b = list(dic.values())[0]
		if b == len(l):
			print(list(dic.keys())[0] ** (b + 1))
		else:
			print(-1)
		return
	tot = 1
	for b in dic.values():
		tot = tot * (b + 1)
	if len(l) + 2 == tot and X not in l:
		print(X)
	else:
		print(-1)
t = int(input())
for i in range(t):
	jebaj()


from math import *

def isqrt(n):
	return floor(sqrt(n))
for _ in range(int(input())):
	a = int(input())
	array = list(map(int, input().split()))
	array.sort()
	if a > 0:
		n = array[0] * array[-1]
	else:
		n = 1
	tmp = []
	for i in range(1, isqrt(n) + 1):
		if n % i == 0:
			tmp.append(i)
			tmp.append(n // i)
	tmp = list(set(tmp))
	tmp.sort()
	if tmp[1:-1] == array:
		print(n)
	else:
		print(-1)


Q = int(input())
q = 0
while q < Q:
	N = int(input())
	arr = input()
	arr = [int(num) for num in arr.split(' ')]
	data = {}
	for num in arr:
		data[num] = 1
	arr.sort()
	left = 0
	right = N - 1
	ans = arr[left] * arr[right]
	left += 1
	right -= 1
	neg = 0
	while left <= right:
		num = arr[left] * arr[right]
		if num != ans:
			neg = 1
		left += 1
		right -= 1
	if neg == 0:
		for i in range(2, 100000):
			if i * i > ans:
				break
			elif ans % i == 0:
				if i not in data or ans // i not in data:
					neg = 1
					break
	if neg == 1:
		print('-1')
	else:
		print(ans)
	q += 1


import math
for test in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	(x, flag) = (a[0] * a[-1], 0)
	for i in range(len(a)):
		if a[i] * a[-1 - i] != x:
			flag = 1
			break
	if flag == 1:
		print(-1)
		continue
	b = []
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			b.append(i)
			if i != x // i:
				b.append(x // i)
	b = sorted(b)
	if len(a) != len(b):
		print(-1)
		continue
	flag = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		print(x)


import math

def divisors(x):
	divs = {1, x}
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			divs.add(i)
			divs.add(x // i)
	return divs
cases = int(input())
for _ in range(cases):
	num = int(input())
	arr = set(map(int, input().split()))
	ans = max(arr) * min(arr)
	arr.update({1, ans})
	if arr == divisors(ans):
		print(ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	ds = list(map(int, input().split()))
	mn = min(ds)
	mx = max(ds)
	x = mn * mx
	d = 2
	xds = []
	while d * d < x:
		if x % d == 0:
			xds.append(d)
			xds.append(x // d)
		d += 1
	if d * d == x:
		xds.append(d)
	if sorted(ds) == sorted(xds):
		print(x)
	else:
		print(-1)


def div(n):
	i = 2
	allfacs = 1
	while i * i <= n:
		fac = 0
		while n % i == 0:
			n //= i
			fac += 1
		if fac:
			allfacs *= fac + 1
		i += 1
	if n > 1:
		allfacs *= 2
	return allfacs
for T in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	flag = 0
	probable = min(a) * max(a)
	for i in a:
		if probable % i != 0:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		d = div(probable)
		if d != n + 2:
			print(-1)
		else:
			print(probable)


def allDvisors(x):
	divisors = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			divisors.append(i)
			if i != x // i:
				divisors.append(x // i)
	return divisors
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	a = arr[0]
	b = arr[-1]
	x = a * b
	divisor = allDvisors(x)
	arr.sort()
	divisor.sort()
	if arr == divisor:
		print(x)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = l[-1] * l[0]
	fact = []
	i = 2
	while i * i <= ans:
		if ans % i == 0:
			fact.append(i)
			if ans // i != i:
				fact.append(ans // i)
		i += 1
	if set(fact) != set(l):
		ans = -1
	print(ans)


import sys
input = sys.stdin.readline
from math import sqrt
q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	x = l[0] * l[-1]
	l = [1] + l + [x]
	ans = set()
	for i in range(1, int(sqrt(x)) + 1):
		if x % i == 0:
			ans.add(i)
			ans.add(x // i)
	ans = sorted(list(set(ans)))
	if l == ans:
		print(x)
	else:
		print(-1)


n = int(input())
answers = [0] * n
for i in range(n):
	d_len = int(input())
	divisors = [int(i) for i in filter(None, input().split())]
	divisors.sort()
	possible_x = divisors[-1] * divisors[0]
	d_count = 0
	for j in range(2, int(possible_x ** 0.5) + 1):
		if possible_x % j == 0:
			d_count += 1
			if j != possible_x // j:
				d_count += 1
	if d_count != d_len:
		answers[i] = -1
	if answers[i] == 0:
		for j in range(d_len // 2):
			if divisors[j] * divisors[d_len - j - 1] != possible_x:
				answers[i] = -1
		if d_len % 2 != 0 and divisors[d_len // 2] ** 2 != possible_x:
			answers[i] = -1
	if answers[i] == 0:
		answers[i] = possible_x
for a in answers:
	print(a)


import math
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	blah = []
	a.sort()
	for i in range(n // 2 + 1):
		if i != n - 1 - i:
			blah.append(a[i] * a[n - 1 - i])
		else:
			blah.append(a[i] * a[i])
	ans = blah[0]
	c1 = blah.count(ans)
	contra = 0
	for i in range(2, int(math.sqrt(ans)) + 1, 1):
		if ans % i == 0:
			if i != 1 and i != ans:
				contra += 1
			if ans // i != 1 and i != ans and (ans // i != i):
				contra += 1
	if c1 == len(blah) and contra == n:
		print(ans)
	else:
		print('-1')


from sys import stdin
from collections import defaultdict

def get_prime_nums():
	prime_nums = [2]
	for i in range(3, 1000):
		is_prime = True
		for num in prime_nums:
			if i % num == 0:
				is_prime = False
				break
		if is_prime:
			prime_nums.append(i)
	return prime_nums

def get_mult(x, prime_nums):
	prime_stats = defaultdict(int)
	for prime_num in prime_nums:
		while x % prime_num == 0 and x != 1:
			prime_stats[prime_num] += 1
			x = x // prime_num
	if x != 1:
		prime_stats[x] += 1
	return prime_stats

def get_nok(d, prime_nums):
	d = sorted(d)
	mn = d[0]
	mx = d[-1]
	nok = mn * mx
	mn_mult = get_mult(mn, prime_nums)
	mx_mult = get_mult(mx, prime_nums)
	nok_mult = mx_mult
	for (num, c) in mn_mult.items():
		nok_mult[num] += c
	total_mult = 1
	for c in nok_mult.values():
		total_mult *= c + 1
	total_mult -= 2
	if len(d) != total_mult:
		return -1
	for i in range((total_mult + 1) // 2):
		if d[i] * d[total_mult - 1 - i] != nok:
			return -1
	return nok
t = int(stdin.buffer.readline())
prime_nums = get_prime_nums()
for _ in range(t):
	n = int(stdin.buffer.readline())
	d = list(map(int, stdin.buffer.readline().split()))
	print(get_nok(d, prime_nums))


sie = [1] * (10 ** 6 + 5)
sie[0] = 0
sie[1] = 0
for i in range(2, 10 ** 3 + 10):
	if sie[i]:
		for j in range(i * i, 10 ** 6 + 5, i):
			sie[j] = 0

def gen(x):
	ans = []
	for i in range(1, x + 2):
		if x % i == 0:
			ans.append(i)
	ans = list(set(ans))
	ans.remove(1)
	ans.remove(x)
	return ans
T = int(input())
for t in range(T):
	n = int(input())
	A = [int(i) for i in input().split()]
	if n == 1 and sie[A[0]]:
		print(A[0] * A[0])
		continue
	elif n == 1:
		print(-1)
		continue
	A.sort()
	ans = A[0] * A[-1]
	from collections import defaultdict as dd
	hsh = dd(int)
	for i in range(n):
		if i <= n - i - 1:
			hsh[A[i] * A[n - i - 1]] = 1
	if len(hsh.keys()) > 1:
		print(-1)
	else:
		op = []
		for i in range(1, int(ans ** 0.5) + 5):
			if ans % i == 0:
				op.append(i)
				op.append(ans // i)
		op = sorted(list(set(op)))
		if op[1:-1] != A:
			print(-1)
			continue
		print(ans)
		continue


def printDivisors(x):
	v = set()
	d = 2
	while d * d <= x:
		if 0 == x % d:
			v.add(d)
			v.add(x / d)
		d += 1
	return v
for j in range(int(input())):
	a = int(input())
	li = list(map(int, input().split()))
	num = max(li) * min(li)
	if set(li) == printDivisors(num):
		print(num)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	data = list(map(int, input().split()))
	dels = []
	val = min(data) * max(data)
	for i in range(2, int(val ** 0.5) + 2):
		if val % i == 0:
			if val // i == i:
				dels.append(i)
			else:
				dels.extend((i, val // i))
	print(val if set(dels) == set(data) else -1)


def primes(limit):
	a = [True] * limit
	a[0] = a[1] = False
	for (i, isprime) in enumerate(a):
		if isprime:
			yield i
			for n in range(i * i, limit, i):
				a[n] = False
t = int(input())
p = set(primes(1000000))
fans = ''
for _ in range(t):
	n = int(input())
	d = sorted(list(map(int, input().split())))
	if d[0] not in p:
		fans += '-1\n'
		continue
	ans = d[0] * d[-1]
	ori = set(d)
	new = set()
	for i in range(2, int(ans ** 0.5) + 1):
		if ans % i == 0:
			new.add(i)
			new.add(ans // i)
	if new == ori:
		fans += str(ans)
		fans += '\n'
	else:
		fans += '-1\n'
print(fans)


for i in range(int(input())):
	n = int(input())
	d = [int(j) for j in input().split()]
	if n == 1:
		j = 2
		while j * j <= d[0]:
			if d[0] % j == 0:
				print(-1)
				break
			j += 1
		else:
			print(d[0] * d[0])
	else:
		d.sort()
		start = 0
		stop = n - 1
		ans = d[start] * d[stop]
		while start <= stop and start < n and (stop > 0):
			if ans != d[start] * d[stop]:
				print(-1)
				break
			start += 1
			stop -= 1
		else:
			fin = 0
			j = 2
			while j * j <= ans:
				if ans % j == 0:
					fin += 1
					if ans // j != j:
						fin += 1
				j += 1
			if fin == n:
				print(ans)
			else:
				print(-1)


t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	x = arr[0] * arr[-1]
	div = []
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			if x // i != i:
				div.append(x // i)
				div.append(i)
			else:
				div.append(i)
	div.sort()
	if div != arr:
		print(-1)
	else:
		print(x)


def main():
	for i in range(int(input())):
		n = int(input())
		arr = sorted([int(i) for i in input().split()])
		val = arr[-1] * arr[0]
		x = -1
		for j in arr:
			if j * arr[x] != val:
				val = -1
				break
			x -= 1
		if val == -1:
			print(val)
		else:
			d = 0
			for j in range(2, int(val ** 0.5) + 1):
				if val % j == 0:
					d += 1
			if d * 2 - n % 2 == n:
				print(val)
			else:
				print(-1)
main()