T=int(input())
R=[]
for i in range(T):
N=int(input())
A=list(map(int,input().split()))
P=[]
def prime(n):
for i in range(2,n):
if(n%i==0):
return -1
break
else:
return 1
for i in range(len(A)):
y=prime(A[i])
if(y==1):
p=0
P.append(A[i])
else:
pass
P.sort()
if(p==0 and prime(P[0]*P[1])==1):
R.append(P[0]*P[1])
else:
R.append(-1)
for i in range(len®):
print(R[i])