The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N).

Find the minimal number x > 1 such that x is a divisor of all integers from array A. More formally, this x should satisfy the following relations:

A[1] mod x = 0, A[2] mod x = 0, ..., A[N] mod x = 0,

where mod stands for the modulo operation. For example,  8 mod 3 = 2,  2 mod 2 = 0, 100 mod 5 = 0 and so on. If such number does not exist, output -1.

-----Input-----

The first line of the input contains a single integer T, the number of test cases. T test cases follow. The first line of each test case contains a single integer N, the size of the array A for the corresponding test case. The second line contains N space separated integers A[1], A[2], ..., A[N].

-----Output-----

For each test case output a single line containing the answer for the corresponding test case.

-----Constraints-----
1 ≤ T ≤ 100000

1 ≤ N ≤ 100000

The sum of values of N in each test file does not exceed 100000

1 ≤ A[i] ≤ 100000

-----Example-----
Input:
2
3
2 4 8
3
4 7 5

Output:
2
-1

-----Explanation-----
Case 1. Clearly 2 is a divisor of each of the numbers 2, 4 and 8. Since 2 is the least number greater than 1 then it is the answer.

Case 2. Let's perform check for several first values of x.

x4 mod x7 mod x5 mod x20113112403154206415740584759475

As we see each number up to 9 does not divide all of the numbers in the array. Clearly all larger numbers also will fail to do this. So there is no such number x > 1 and the answer is -1.

Difficulty: MEDIUM_HARD
Tags: Number theory

Mathematics

Starter code:

Solutions:
import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = l[0]
	for i in range(1, n):
		s = math.gcd(s, l[i])
	if s == 1:
		print(-1)
	elif s % 2 == 0:
		print(2)
	else:
		ans = 0
		for i in range(3, int(s ** 0.5) + 1):
			if s % i == 0:
				ans = i
				break
		if ans == 0:
			print(s)
		else:
			print(ans)


from functools import reduce
from math import gcd, sqrt
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	gcd_ = reduce(gcd, l)
	if gcd_ == 1:
		print(-1)
	else:
		for i in range(2, int(sqrt(gcd_)) + 1):
			if gcd_ % i == 0:
				print(i)
				break
		else:
			print(gcd_)


import math

def get_gcd(a, b):
	if b == 0:
		return a
	return get_gcd(b, a % b)
T = int(input())
for t in range(T):
	(n, gcd) = (int(input()), 0)
	arr = list(map(int, input().split()))
	for e in arr:
		gcd = get_gcd(gcd, e)
	ans = gcd
	for i in range(2, math.floor(math.sqrt(gcd)) + 1):
		if gcd % i == 0:
			ans = i
			break
	print(-1 if ans == 1 else ans)


import functools
import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	g_1 = functools.reduce(math.gcd, l)
	if g_1 == 1:
		print(-1)
		continue
	t_1 = int(math.sqrt(g_1))
	c = 0
	for i in range(2, t_1 + 2):
		if g_1 % i == 0:
			c = i
			break
	if c == 0:
		print(g_1)
	else:
		print(c)


import math

def hcf(a, b):
	if a == 0:
		return 1
	if a % b == 0:
		return b
	return hcf(b, a % b)
t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	curr = list1[0]
	for i in range(1, n):
		curr = hcf(curr, list1[i])
		if curr == 1:
			break
	if curr == 1:
		print(-1)
	else:
		ans = -1
		for i in range(2, math.floor(math.sqrt(curr)) + 1):
			if curr % i == 0:
				ans = i
				break
		if ans == -1:
			print(curr)
		else:
			print(i)


def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
for ii in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	g = arr[0]
	for i in range(1, n):
		g = gcd(g, arr[i])
		if g == 1:
			break
	ans = g
	if g == 1:
		ans = -1
	else:
		for i in range(2, int(g ** 0.5) + 1):
			if g % i == 0:
				ans = i
				break
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	arr = [int(a) for a in input().split()]
	if n == 1:
		g = arr[0]
	else:
		g = math.gcd(arr[0], arr[1])
		for i in range(2, n):
			g = math.gcd(g, arr[i])
	if g == 1:
		print(-1)
	else:
		final = 0
		for i in range(2, int(math.sqrt(g)) + 2):
			if g % i == 0:
				final = i
				break
		if final == 0:
			print(g)
		else:
			print(final)


import math
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	g = a[0]
	for i in range(n):
		g = math.gcd(g, a[i])
		if g == 1:
			print(-1)
			break
	else:
		for i in range(2, int(math.sqrt(g) + 1)):
			if g % i == 0:
				print(i)
				break
		else:
			print(g)


import math
test = int(input())
for _ in range(test):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(1, n):
		l[i] = math.gcd(l[i], l[i - 1])
	a = l[-1]
	if a == 1:
		print(-1)
	else:
		f = 0
		p = int(math.sqrt(l[-1]))
		i = 2
		while i <= p:
			if a % i == 0:
				print(i)
				f = 1
				break
			i += 1
		if f == 0:
			print(a)


from math import gcd, sqrt
LIMIT = 100001
lowest_prime = [i for i in range(LIMIT)]
for i in range(2, LIMIT):
	if lowest_prime[i] == i:
		for j in range(2 * i, LIMIT, i):
			lowest_prime[j] = min(lowest_prime[j], i)
for _ in range(int(input())):
	curr = int(input())
	arrs = [int(x) for x in input().split()]
	gc_d = 0
	for i in arrs:
		gc_d = gcd(gc_d, i)
	print(-1 if gc_d == 1 else lowest_prime[gc_d])


from math import *
for j in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	a = x[0]
	am = 0
	for i in range(1, n):
		a = gcd(a, x[i])
	if a == 1:
		print(-1)
	else:
		for i in range(2, int(sqrt(a)) + 1):
			if a % i == 0:
				print(i)
				am = 1
				break
		if am == 0:
			print(a)


import math

def minFactor(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	num = a[0]
	for i in range(1, n):
		num = math.gcd(num, a[i])
		if num == 1:
			print('-1')
			break
	else:
		if num == 1:
			print('-1')
		else:
			print(minFactor(num))


from math import gcd, sqrt
for _ in range(int(input())):
	N = int(input())
	array = list(map(int, input().split()))
	if N == 1:
		g = array[0]
	else:
		g = gcd(array[0], array[1])
		for i in range(2, N):
			g = gcd(g, array[i])
	if g == 1:
		print(-1)
	else:
		ans = 0
		for i in range(2, int(sqrt(g)) + 2):
			if g % i == 0:
				ans = i
				break
		if ans == 0:
			print(g)
		else:
			print(ans)


from functools import reduce
from math import sqrt
from math import gcd
for i in range(int(input())):
	n = int(input())
	li = list((int(i) for i in input().split()))
	a = reduce(lambda a, b: gcd(a, b), li)
	if a == 1:
		print(-1)
	else:
		for i in range(2, int(sqrt(a)) + 1):
			if a % i == 0:
				print(i)
				break
		else:
			print(a)


from sys import stdin, stdout
import math
from collections import Counter
import functools
import time
from functools import reduce

def tr():
	return range(int(line()))

def sm():
	return map(int, line().split())

def ln():
	return list(sm())

def nl():
	return int(line())

def ssm():
	return map(str, line().split())

def line():
	return stdin.readline().rstrip()

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

def o(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + '\n')

def osp(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + ' ')

def ol(x):
	stdout.write(' '.join(map(str, x)) + '\n')

def smallest_prime_factor(max_n):
	primes = [False, True] * (max_n // 2 + 1)
	primes[2] = True
	smallest = [i for i in range(max_n)]
	for i in range(2, max_n, 2):
		smallest[i] = 2
	p = 3
	while p * p < max_n:
		if primes[p]:
			for i in range(p, max_n, p):
				primes[i] = False
				smallest[i] = min(smallest[i], p)
		p += 2
	return smallest

def main():
	smallest = smallest_prime_factor(100000 + 1)
	for _ in tr():
		n = nl()
		a = ln()
		common = reduce(math.gcd, a)
		if common == 1:
			print(-1)
		else:
			print(smallest[common])
main()


import math
T = int(input())
while T:
	N = int(input())
	A = list(map(int, input().split()))
	hcf = A[0]
	n = len(A)
	for i in range(1, len(A)):
		hcf = math.gcd(hcf, A[i])
	if hcf == 1:
		print(-1)
	elif hcf % 2 == 0:
		print(2)
	else:
		answer = 0
		for j in range(3, int(hcf ** 0.5) + 1):
			if hcf % j == 0:
				answer = j
				break
		if answer == 0:
			print(hcf)
		else:
			print(answer)
	T -= 1


from functools import reduce
from math import gcd

def sieve(n):
	start = int(n ** 0.5) + 2
	arr = [True] * (n + 1)
	primes = []
	for i in range(2, start):
		if arr[i] == True:
			primes.append(i)
		for j in range(i * 2, n + 1, i):
			arr[j] = False
	for i in range(start, n + 1):
		if arr[i] == True:
			primes.append(i)
	return primes

def divs(n, primes):
	sq = n ** 0.5
	fac = []
	for i in primes:
		if i > sq:
			break
		if n % i == 0:
			fac.append(i)
	if len(fac) == 0:
		fac = [n]
	return fac
primes = sieve(int((10 ** 5) ** 0.5 + 1))
for _ in range(int(input())):
	n = int(input())
	ls = [int(X) for X in input().split()]
	gc = reduce(gcd, ls)
	x = divs(gc, primes)
	if x[0] != 1:
		print(x[0])
	elif x[0] == 1 and len(x) > 1:
		print(x[1])
	else:
		print(-1)


from math import gcd, sqrt
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	g = l[0]
	for j in l:
		g = gcd(j, g)
	if g == 1:
		ans = -1
	else:
		ans = g
		for k in range(2, int(sqrt(g)) + 1):
			if g % k == 0:
				ans = k
				break
	print(ans)


from math import *
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	g = l[0]
	for i in range(1, n):
		g = gcd(g, l[i])
	if g == 1:
		print(-1)
	else:
		x = g
		for i in range(2, int(sqrt(g)) + 1):
			if g % i == 0:
				x = i
				break
		print(x)


from math import gcd, sqrt
for _ in range(int(input())):
	s = 0
	f = 1
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(len(a)):
		s = gcd(s, a[i])
	if s == 1:
		print(-1)
	else:
		for i in range(2, int(sqrt(s)) + 1):
			if s % i == 0:
				print(i)
				f = 0
				break
		if f == 1:
			print(s)


import math
test = int(input())
for _ in range(test):
	n = int(input())
	array = list(map(int, input().split()))
	hcf = array[0]
	for i in range(1, n):
		hcf = math.gcd(hcf, array[i])
	if hcf == 1:
		print(-1)
	elif hcf % 2 == 0:
		print(2)
	else:
		answer = 0
		for i in range(3, int(hcf ** 0.5) + 1):
			if hcf % i == 0:
				answer = i
				break
		if answer == 0:
			print(hcf)
		else:
			print(answer)


import math
for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	a = list(a)
	x = a[0]
	for i in a:
		x = math.gcd(i, x)
	if x == 1:
		k = -1
	else:
		k = x
		x1 = x ** 0.5
		t = int(x1)
		for i in range(2, t + 1):
			if x % i == 0:
				k = i
				break
	print(k)


from math import gcd
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	g = l[0]
	for x in l:
		g = gcd(x, g)
	if g == 1:
		print(-1)
	elif g % 2 == 0:
		print(2)
	else:
		for i in range(3, int(g ** 0.5) + 1):
			if g % i == 0:
				print(i)
				break
		else:
			print(g)


import math
for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	g = 0
	flag = 0
	for i in list1:
		g = math.gcd(g, i)
	if g == 1:
		print('-1')
	else:
		for i in range(2, int(g ** (1 / 2)) + 1):
			if g % i == 0:
				flag = 1
				print(i)
				break
		if flag == 0:
			print(g)


import math
T = int(input())
for i in range(T):
	N = int(input())
	s = list(map(int, input().split()))
	gcd = 0
	for j in s:
		gcd = math.gcd(gcd, j)
	if gcd == 1:
		print(-1)
	else:
		for p in range(2, math.floor(math.sqrt(gcd)) + 1):
			if gcd % p == 0:
				print(p)
				break
		else:
			print(gcd)


from functools import reduce
from math import gcd

def divisor(n):
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	n = int(input())
	ls = [int(X) for X in input().split()]
	gc = reduce(gcd, ls)
	if gc == 1:
		print(-1)
	elif gc % 2 == 0:
		print(2)
	else:
		print(divisor(gc))


t = int(input())
import math
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	gcd = 0
	for i in l:
		gcd = math.gcd(gcd, i)
	if gcd == 1:
		print(-1)
	else:
		for j in range(2, math.floor(math.sqrt(gcd)) + 1):
			if gcd % j == 0:
				print(j)
				break
		else:
			print(gcd)
	t = t - 1


from sys import stdin, stdout
import math as m
input = stdin.readline
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	gcd = arr[0]
	for num in arr:
		gcd = m.gcd(gcd, num)
	if gcd == 1:
		print(-1)
		continue
	ans = gcd
	for i in range(2, m.ceil(m.sqrt(gcd)) + 1):
		if gcd % i == 0:
			ans = min(ans, i)
	print(ans)


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	for i in a:
		x = math.gcd(i, x)
	if x == 1:
		k = -1
	else:
		k = x
		x1 = x ** 0.5
		t = int(x1)
		for i in range(2, t + 1):
			if x % i == 0:
				k = i
				break
	print(k)

def __starting_point():
	t = int(input())
	while t != 0:
		solve()
		t -= 1
__starting_point()


import math
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	res = l[0]
	for j in range(1, n):
		res = math.gcd(res, l[j])
	if res == 1:
		print(-1)
	else:
		flag = 0
		x = 0
		for j in range(2, int(math.sqrt(res)) + 1):
			if res % j == 0:
				x = j
				flag = 1
				break
		if flag == 1:
			print(x)
		else:
			print(res)


from math import gcd
from functools import reduce
max = 10 ** 5 + 1
sieve = [i for i in range(max)]
for i in range(2, max):
	if sieve[i] == i:
		j = 2
		while j * i < max:
			sieve[i * j] = min(sieve[i * j], i)
			j += 1
t = int(input())
l = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	g = reduce(gcd, a)
	if g == 1:
		l.append(-1)
	else:
		l.append(sieve[g])
for _ in l:
	print(_)


import math

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

def primeNO(n):
	a = math.floor(math.sqrt(n))
	for i in range(2, math.floor(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	x = l[0]
	count = 0
	for j in range(1, n):
		x = gcd(x, l[j])
	count = primeNO(x)
	if count == 1:
		print(-1)
	else:
		print(count)


from math import gcd, sqrt
T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	A = [int(i) for i in input().split()]
	g = A[0]
	for i in range(1, N):
		g = gcd(g, A[i])
	f = g
	for i in range(2, int(sqrt(g)) + 1):
		if g % i == 0:
			f = i
			break
	if g != 1:
		ans.append(f)
	else:
		ans.append(-1)
for i in ans:
	print(i)


import math
lim = 100001
smallest_factor = [i for i in range(lim)]
smallest_factor[0] = 0
for i in range(2, int(math.sqrt(lim)) + 1):
	if smallest_factor[i] == i:
		for j in range(i * i, lim, i):
			if smallest_factor[j] == j:
				smallest_factor[j] = i

def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	res = None
	if n == 1:
		res = smallest_factor[a[0]]
	else:
		hcf = gcd(a[0], a[1])
		for i in range(2, n):
			hcf = gcd(hcf, a[i])
		res = smallest_factor[hcf]
	if res == 1:
		print(-1)
	else:
		print(res)


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	gcd = 0
	for i in arr:
		gcd = math.gcd(gcd, i)
	if gcd == 1:
		print(-1)
	else:
		r = int(math.sqrt(gcd)) + 1
		for j in range(2, r):
			if gcd % j == 0:
				gcd = j
				break
		print(gcd)


from math import sqrt, gcd
for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	g = ar[0]
	for i in range(1, n):
		g = gcd(g, ar[i])
	f = g
	for i in range(2, int(sqrt(g)) + 1):
		if g % i == 0:
			f = i
			break
	if g != 1:
		print(f)
	else:
		print(-1)


from math import sqrt

def gcdd(x, y):
	if y == 0:
		return x
	return gcdd(y, x % y)

def main(a):
	one = a[0]
	gcd = a[0]
	for i in range(1, len(a)):
		gcd = gcdd(gcd, a[i])
		if gcd == 1:
			return 1
	return gcd
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = main(a)
	if t == 1:
		print(-1)
	else:
		for i in range(2, int(sqrt(t)) + 2):
			if t % i == 0:
				t = i
				break
		print(t)


def compute_gcd(a, b):
	if not b:
		return a
	elif not a:
		return b
	return compute_gcd(b, a % b)

def compute_min_divisor(sequence):
	seq_gcd = 0
	for value in sequence:
		seq_gcd = compute_gcd(seq_gcd, value)
	if seq_gcd == 1:
		return -1
	min_divisor = seq_gcd
	i = 2
	while i * i <= seq_gcd:
		if not seq_gcd % i:
			min_divisor = i
			break
		i += 1
	return min_divisor

def main():
	for test in range(int(input().rstrip())):
		n = int(input().rstrip())
		print('{}'.format(compute_min_divisor(list(map(int, input().rstrip().split())))))
main()


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] == 1:
		print(-1)
	else:
		l1 = [l[0]]
		flag = 0
		for i in range(1, n):
			p = math.gcd(l1[-1], l[i])
			if p == 1:
				print(-1)
				flag = 1
				break
			else:
				l1.append(p)
		if flag == 0:
			p = l1[-1]
			for i in range(2, int(p ** 0.5) + 1):
				if p % i == 0:
					print(i)
					flag = 1
					break
		if flag == 0:
			print(p)


from math import gcd, sqrt
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	div = arr[0]
	for i in range(n):
		div = gcd(arr[i], div)
	if div == 1:
		print(-1)
	else:
		for i in range(2, int(sqrt(div)) + 1):
			if div % i == 0:
				print(i)
				break
		else:
			print(div)


from math import gcd
from functools import reduce
MAX = 10 ** 5 + 1
sieve = [i for i in range(MAX)]
for i in range(2, MAX):
	if sieve[i] == i:
		j = 2
		while i * j < MAX:
			sieve[i * j] = min(sieve[i * j], i)
			j += 1
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	g = reduce(gcd, a)
	if g == 1:
		print(-1)
	else:
		print(sieve[g])


def g(a, b):
	if a == 0:
		return b
	return g(b % a, a)
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	gcd = l[0]
	for i in l:
		gcd = g(gcd, i)
	if gcd == 1:
		print(-1)
	else:
		i = 2
		ans = -1
		while i * i <= gcd:
			if gcd % i == 0:
				ans = i
				break
			i += 1
		if ans == -1:
			print(gcd)
		else:
			print(min(gcd, ans))


def hcf(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
is_prime = [True] * (100000 + 2)
primes = []
is_prime[0] = False
is_prime[1] = False
for i in range(2, 100000 + 2):
	if is_prime[i]:
		primes.append(i)
		for j in range(i * i, 100000 + 2, i):
			is_prime[j] = False
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	factor = l[0]
	for i in l:
		factor = hcf(factor, i)
	if factor == 1:
		print(-1)
	elif is_prime[factor]:
		print(factor)
	else:
		for i in primes:
			if factor % i == 0:
				print(i)
				break


from math import gcd, sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	g = arr[0]
	for i in arr:
		g = gcd(i, g)
	if g == 1:
		ans = -1
	else:
		ans = g
		for i in range(2, int(sqrt(g)) + 1):
			if g % i == 0:
				ans = i
				break
	print(ans)


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

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

def answer(n):
	print(n if n > 1 else -1)
TC = int(input())
for _ in range(TC):
	N = int(input().strip())
	arr = list(map(int, input().strip().split()))
	if N == 1:
		answer(getMinFactor(arr[0]))
		continue
	g = gcd(arr[0], arr[1])
	for i in range(2, N):
		g = gcd(g, arr[i])
		if g == 1:
			break
	answer(getMinFactor(g))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	p = dict()
	uni = []
	for i in range(0, len(arr)):
		nn = arr[i]
		if nn % 2 == 0:
			if p.get(2) == None:
				p[2] = 1
				uni.append(2)
			else:
				p[2] += 1
			while nn % 2 == 0:
				nn = nn // 2
		for j in range(3, int(math.sqrt(nn)) + 1, 2):
			if nn % j == 0:
				if p.get(j) == None:
					p[j] = 1
					uni.append(j)
				else:
					p[j] += 1
				while nn % j == 0:
					nn //= j
		if nn > 2:
			if p.get(nn) == None:
				p[nn] = 1
				uni.append(nn)
			else:
				p[nn] += 1
	ans = -1
	for i in range(0, len(uni)):
		if p[uni[i]] == n:
			ans = uni[i]
			break
	print(ans)


from math import gcd
MAX = 100001
sp = [0] * MAX

def sieve():
	sp[0] = 1
	sp[1] = -1
	i = 2
	while i * i < MAX:
		if sp[i] == 0:
			for j in range(2 * i, MAX, i):
				if sp[j] == 0:
					sp[j] = i
		i += 1
	for i in range(2, MAX):
		if sp[i] == 0:
			sp[i] = i

def calgcd(L):
	res = 0
	for i in L:
		res = gcd(res, i)
	return sp[res]
sieve()
T = int(input())
while T > 0:
	N = int(input())
	L = list(map(int, input().split()))
	print(calgcd(L))
	T -= 1


import math

def divisors(n):
	if n == 1:
		return []
	l = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			l.append(i)
			l.append(n // i)
	l.append(n)
	l = sorted(l)
	return l
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	raj = set(divisors(arr[0]))
	for i in range(1, n):
		temp = set()
		for j in raj:
			if arr[i] % j == 0:
				temp.add(j)
		raj = raj.intersection(temp)
	if len(raj) != 0:
		raj = sorted(list(raj))
		for i in raj:
			print(i)
			break
	else:
		print(-1)


import math
for _ in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	l.sort()
	z = int(math.sqrt(l[0]))
	l1 = []
	for i in range(1, z + 1):
		if l[0] % i == 0:
			l1.append(i)
			l1.append(l[0] // i)
	l1.sort()
	(f, o) = (0, 0)
	for i in range(len(l1)):
		k = 0
		for j in range(len(l)):
			if l1[i] != 1:
				if l[j] % l1[i] == 0:
					k += 1
				else:
					break
		if k == len(l):
			f += 1
			o = l1[i]
			break
	if f == 0:
		print(-1)
	else:
		print(o)


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

def mina(x):
	for j in range(2, int(x ** 0.5) + 1):
		if x % j == 0:
			return j
	return x
for i in range(int(input())):
	x = int(input())
	a = list(map(int, input().strip().split()))
	s = a[0]
	if x == 1:
		s = mina(a[0])
	else:
		for j in a[1:]:
			s = gcd(s, j)
			if s == 1:
				break
	if s == 1:
		print(-1)
	else:
		print(mina(s))


T = int(input())
for i in range(T):
	N = int(input())
	A = list(map(lambda x: int(x), str(input()).split(' ')))
	A.sort()
	dictone = {}
	for j in range(N):
		k = 2
		while k * k <= A[j]:
			if A[j] % k == 0:
				dictone[k] = dictone.get(k, 0) + 1
				while A[j] % k == 0:
					A[j] = A[j] // k
			k = k + 1
		if A[j] != 1:
			dictone[A[j]] = dictone.get(A[j], 0) + 1
	aa = list(dictone.items())
	if len(aa):
		aa.sort(key=lambda x: x[0])
		aa.sort(key=lambda x: x[1], reverse=True)
		if aa[0][1] == N:
			print(aa[0][0])
		else:
			print(-1)
	else:
		print(-1)