You are given an array $a$ consisting of $n$ positive integers. You have to choose a positive integer $d$ and paint all elements into two colors. All elements which are divisible by $d$ will be painted red, and all other elements will be painted blue.

The coloring is called beautiful if there are no pairs of adjacent elements with the same color in the array. Your task is to find any value of $d$ which yields a beautiful coloring, or report that it is impossible.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.

The first line of each testcase contains one integer $n$ ($2 \le n \le 100$) — the number of elements of the array.

The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{18}$).


-----Output-----

For each testcase print a single integer. If there is no such value of $d$ that yields a beautiful coloring, print $0$. Otherwise, print any suitable value of $d$ ($1 \le d \le 10^{18}$).


-----Examples-----

Input
5
5
1 2 3 4 5
3
10 5 15
3
100 10 200
10
9 8 2 6 6 2 8 6 5 4
2
1 3
Output
2
0
100
0
3


-----Note-----

None

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = il()
	g = 0
	g1 = 0
	for i in range(0, n, 2):
		g = gcd(g, a[i])
	for i in range(1, n, 2):
		g1 = gcd(g1, a[i])
	if g == g1:
		print(0)
	else:
		fl = 0
		fl1 = 0
		if 1:
			for i in range(1, n, 2):
				if a[i] % g == 0:
					fl = 1
					break
		if 1:
			for i in range(0, n, 2):
				if a[i] % g1 == 0:
					fl1 = 1
					break
		if fl and fl1:
			print(0)
		elif fl:
			print(g1)
		else:
			print(g)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
A = [12, 24, 27, 30, 36]
res = A[0]
for c in A[1:]:
	res = gcd(res, c)
n = int(input())
for i in range(n):
	found = True
	num = int(input())
	ans = 0
	fin = 0
	x = [int(i) for i in input().split()]
	gc = x[0]
	for i in x[2::2]:
		gc = gcd(gc, i)
	if gc != 1:
		for i in x[1::2]:
			if i % gc == 0:
				found = False
				break
	else:
		found = False
	if not found:
		gc = x[1]
		found = True
		for i in x[3::2]:
			gc = gcd(gc, i)
		for i in x[::2]:
			if i % gc == 0:
				found = False
				break
	if found:
		print(gc)
	else:
		print(0)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	gcd = [a[0], a[1]]
	for i in range(2, n):
		gcd[i % 2] = math.gcd(gcd[i % 2], a[i])
	f1 = True
	f2 = True
	for i in range(0, n):
		if i % 2 == 0:
			if a[i] % gcd[1] == 0:
				f1 = False
		elif a[i] % gcd[0] == 0:
			f2 = False
	if f1:
		print(gcd[1])
	elif f2:
		print(gcd[0])
	else:
		print(0)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(1, ii() + 1):
		n = ii()
		a = li()
		(x1, x2) = (a[0], a[1])
		for i in range(2, n):
			if i % 2:
				x2 = gcd(x2, a[i])
			else:
				x1 = gcd(x1, a[i])
		ok = True
		for i in range(n):
			if i % 2 and a[i] % x1 == 0:
				ok = False
				break
		if ok:
			print(x1)
			continue
		ok = True
		for i in range(n):
			if i % 2 == 0 and a[i] % x2 == 0:
				ok = False
				break
		if ok:
			print(x2)
		else:
			print(0)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


t = int(input())
import math
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	oddpos = []
	evenpos = []
	(flag1, flag2) = (0, 0)
	ans = 0
	for j in range(0, len(l), 2):
		evenpos.append(l[j])
	for j in range(1, len(l), 2):
		oddpos.append(l[j])

	def gcd(a, b):
		if b == 0:
			return a
		else:
			return gcd(b, a % b)
	resodd = oddpos[0]
	reseven = evenpos[0]
	for c in oddpos[1:]:
		resodd = gcd(resodd, c)
	for c in evenpos[1:]:
		reseven = gcd(reseven, c)
	if resodd != 1:
		for j in range(len(evenpos)):
			if evenpos[j] % resodd == 0:
				flag1 = 1
		if flag1 == 0:
			ans = resodd
	if reseven != 1:
		for j in range(len(oddpos)):
			if oddpos[j] % reseven == 0:
				flag2 = 1
		if flag2 == 0:
			ans = reseven
	print(ans)


import math
tc = int(input())
for tt in range(tc):
	n = int(input())
	l = list(map(int, input().split()))
	gcd = l[1]
	for i in range(3, n, 2):
		gcd = math.gcd(gcd, l[i])
	f = 0
	for i in range(0, n, 2):
		if l[i] % gcd == 0:
			f = 1
			break
	if f == 1:
		gcd = l[0]
		for i in range(2, n, 2):
			gcd = math.gcd(l[i], gcd)
		f = 0
		for i in range(1, n, 2):
			if l[i] % gcd == 0:
				f = 1
				break
		if f == 1:
			print(0)
		else:
			print(gcd)
	else:
		print(gcd)


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

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

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

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

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

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 6):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for i in range(num):
	n = getInt()
	arr = zzz()
	one = arr[::2]
	two = arr[1::2]
	pos1 = True
	pos2 = True
	ans1 = one[0]
	ans2 = two[0]
	for i in one:
		ans1 = gcd(ans1, i)
	for i in two:
		ans2 = gcd(ans2, i)
	for i in two:
		if i % ans1 == 0:
			pos1 = False
	for i in one:
		if i % ans2 == 0:
			pos2 = False
	if pos1:
		print(ans1)
	elif pos2:
		print(ans2)
	else:
		print(0)


import math

def gc(arr):
	an = arr[0]
	for j in range(1, len(arr)):
		an = math.gcd(an, arr[j])
	return an
for j in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ev = []
	od = []
	i = 0
	while i < n:
		if i % 2 == 0:
			od.append(arr[i])
		else:
			ev.append(arr[i])
		i += 1
	evg = gc(ev)
	odg = gc(od)
	ok = -1
	for i in ev:
		if i % odg == 0:
			ok = 0
			break
	if ok != 0:
		print(odg)
		continue
	ok = -1
	for i in od:
		if i % evg == 0:
			ok = 0
			break
	if ok != 0:
		print(evg)
	else:
		print(0)


from sys import stdin, stdout, setrecursionlimit
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
from bisect import bisect_right as br, bisect_left as bl
from heapq import *
mod = 10 ** 9 + 7
inf = 1 << 60

def hcf(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(it()):
	n = it()
	l = mp()
	o = 0
	e = 0
	for i in range(n):
		if i & 1:
			o = hcf(l[i], o)
		else:
			e = hcf(l[i], e)
	flag = 0
	if o == e:
		print(0)
		continue
	for i in range(n):
		if not i & 1:
			if l[i] % o == 0:
				flag = 1
				break
	if not flag:
		print(o)
		continue
	flag = 0
	for i in range(n):
		if i & 1:
			if l[i] % e == 0:
				flag = 1
				break
	if flag:
		print(0)
	else:
		print(e)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = [int(i) for i in input().split()]
	a = lst[::2]
	b = lst[1::2]
	a1 = a[0]
	b1 = b[0]
	for i in a[1:]:
		n1 = i
		n2 = a1
		while 0 != n1 and 0 != n2:
			if n1 < n2:
				(n1, n2) = (n2, n1)
			n1 = n1 % n2
		a1 = max(n1, n2)
	for i in b[1:]:
		n1 = i
		n2 = b1
		while 0 != n1 and 0 != n2:
			if n1 < n2:
				(n1, n2) = (n2, n1)
			n1 = n1 % n2
		b1 = max(n1, n2)
	s1 = list(filter(lambda x: x % b1 == 0, a))
	s2 = list(filter(lambda x: x % a1 == 0, b))
	if len(s1) == 0:
		print(b1)
	elif len(s2) == 0:
		print(a1)
	else:
		print(0)


import math

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	g1 = []
	g2 = []
	gcd1 = int()
	gcd2 = int()
	for i in range(int(len(a))):
		if i % 2 == 0:
			g1.append(a[i])
		else:
			g2.append(a[i])
	if int(len(g1)) > 1:
		gcd1 = find_gcd(g1[0], g1[1])
		for i in range(2, len(g1)):
			gcd1 = find_gcd(gcd1, g1[i])
	else:
		gcd1 = g1[0]
	nextstep = 0
	for i in g2:
		if i % gcd1 == 0:
			nextstep = 1
	if nextstep == 0:
		print(gcd1)
		continue
	if int(len(g2)) > 1:
		gcd2 = find_gcd(g2[0], g2[1])
		for i in range(2, len(g2)):
			gcd2 = find_gcd(gcd2, g2[i])
	else:
		gcd2 = g2[0]
	nextstep = 0
	for i in g1:
		if i % gcd2 == 0:
			nextstep = 1
	if nextstep == 0:
		print(gcd2)
	else:
		print(0)


from sys import stdin
from math import gcd
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	(g1, g2) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			g1 = gcd(g1, a[i])
		else:
			g2 = gcd(g2, a[i])
	for i in range(1, n, 2):
		if a[i] % g1 == 0:
			break
	else:
		print(g1)
		continue
	for i in range(0, n, 2):
		if a[i] % g2 == 0:
			break
	else:
		print(g2)
		continue
	print(0)


import math

def gcd(a):
	x = 0
	for p in a:
		x = math.gcd(x, p)
	return x
for _ in range(int(input())):
	n = input()
	(*a,) = map(int, input().split())
	(e, o) = (a[::2], a[1::2])
	(g1, g2) = (gcd(e), gcd(o))
	if g2 != 0 and all((x % g2 != 0 for x in e)):
		print(g2)
	elif g1 != 0 and all((x % g1 != 0 for x in o)):
		print(g1)
	else:
		print(0)


from math import gcd

def gcd_list(lista):
	length = len(lista)
	if length == 1:
		return lista[0]
	else:
		my_gcd = lista[0]
		for i in range(1, length):
			my_gcd = gcd(my_gcd, lista[i])
		return my_gcd
tc = int(input())
for case in range(tc):
	n = int(input())
	my_numbers = [int(i) for i in input().split()]
	impares = [my_numbers[j] for j in range(n) if j % 2 == 1]
	pares = [my_numbers[k] for k in range(n) if k % 2 == 0]
	gcd_impares = gcd_list(impares)
	gcd_pares = gcd_list(pares)
	flag = 1
	for num in pares:
		if num % gcd_impares == 0:
			flag = 0
	if flag == 1:
		print(gcd_impares)
		continue
	flag = 1
	for num in impares:
		if num % gcd_pares == 0:
			flag = 0
	if flag == 1:
		print(gcd_pares)
	else:
		print(0)


from functools import reduce
from math import gcd

def Solve():
	n = int(input())
	arr1 = list(map(int, input().split()))
	(oddPos, evenPos) = (list(), list())
	check = True
	for i in range(n):
		if check:
			check = False
			oddPos.append(arr1[i])
		else:
			check = True
			evenPos.append(arr1[i])
	gcd1 = reduce(lambda x, y: gcd(x, y), oddPos)
	gcd2 = reduce(lambda x, y: gcd(x, y), evenPos)
	(check1, check2) = (True, True)
	for val1 in evenPos:
		if val1 % gcd1 == 0:
			check1 = False
			break
	if check1:
		print(gcd1)
		return
	for val2 in oddPos:
		if val2 % gcd2 == 0:
			check2 = False
			break
	if check2:
		print(gcd2)
		return
	print(0)
for _ in range(int(input())):
	Solve()


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))

	def gcd(a):
		x = 0
		for i in a:
			x = math.gcd(x, i)
		return x
	(e, o) = (a[::2], a[1::2])
	(g1, g2) = (gcd(e), gcd(o))
	if g1 != 0 and all((x % g1 != 0 for x in o)):
		print(g1)
	elif g2 != 0 and all((x % g2 != 0 for x in e)):
		print(g2)
	else:
		print(0)
t = int(input())
for i in range(t):
	solve()


def hcf(a, b):
	if a % b == 0:
		return b
	return hcf(b, a % b)
t = int(input())
for ii in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	num1 = l[0]
	for i in range(2, n, 2):
		num1 = hcf(num1, l[i])
	num2 = l[1]
	for i in range(3, n, 2):
		num2 = hcf(num2, l[i])
	tf = False
	for i in range(0, n, 2):
		if l[i] % num2 == 0:
			tf = True
			break
	tf2 = False
	for i in range(1, n, 2):
		if l[i] % num1 == 0:
			tf2 = True
			break
	if tf and (not tf2):
		print(num1)
	elif tf2 and (not tf):
		print(num2)
	elif tf2 and tf:
		print(0)
	else:
		print(max(num1, num2))


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

def gcd(arr):
	result = arr[0]
	for i in range(1, len(arr)):
		result = gcd2(arr[i], result)
		if result == 1:
			return 1
	return result
T = int(input())
for t in range(T):
	n = int(input())
	nums = [int(x) for x in input().split(' ')]
	a = nums[0:len(nums):2]
	b = nums[1:len(nums):2]
	d = gcd(a)
	if d > 1 and (not any([i % d == 0 for i in b])):
		print(d)
		continue
	d = gcd(b)
	if d > 1 and (not any([i % d == 0 for i in a])):
		print(d)
		continue
	print(0)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	ans = a[0]
	for i in range(2, n, 2):
		ans = math.gcd(ans, a[i])
	chk = True
	for i in range(1, n, 2):
		if a[i] % ans == 0:
			chk = False
			break
	ans1 = a[1]
	for i in range(3, n, 2):
		ans1 = math.gcd(ans1, a[i])
	chk1 = True
	for i in range(0, n, 2):
		if a[i] % ans1 == 0:
			chk1 = False
			break
	if chk:
		print(ans)
	elif chk1:
		print(ans1)
	else:
		print(0)


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

def split(word):
	return [char for char in word]

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 main():
	for i in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b1 = a[0]
		b2 = a[1]
		for j in range(2, n):
			if j % 2 == 0:
				b1 = math.gcd(b1, a[j])
			else:
				b2 = math.gcd(b2, a[j])
		c1 = 0
		c2 = 0
		for j in range(n):
			if j % 2 == 0:
				if a[j] % b2 == 0:
					c1 = c1 + 1
			elif a[j] % b1 == 0:
				c2 = c2 + 1
		if c1 > 0 and c2 > 0:
			print('0')
		elif c1 == 0:
			print(b2)
		else:
			print(b1)
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()


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	t1 = odd[0]
	lo = len(odd)
	le = len(even)
	for i in range(1, lo):
		t0 = math.gcd(t1, odd[i])
		t1 = t0
	t2 = even[0]
	for i in range(1, le):
		t0 = math.gcd(t2, even[i])
		t2 = t0
	f1 = True
	i = 0
	while f1 and i < le:
		if even[i] % t1 == 0:
			f1 = False
		i += 1
	f2 = True
	j = 0
	while f2 and j < lo:
		if odd[j] % t2 == 0:
			f2 = False
		j += 1
	if f1 and f2:
		print(max(t1, t2))
	elif f1:
		print(t1)
	elif f2:
		print(t2)
	else:
		print(0)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
yy = lambda : print('YES')
nn = lambda : print('NO')
from math import log10, log2, ceil, factorial as fac, gcd, inf, sqrt, log, floor
from bisect import bisect_right as br, bisect_left as bl, insort
from collections import Counter
mod = 10 ** 9 + 7

def Nprime(n):
	if n == 2 or n == 3:
		return 0
	if n == 1:
		return 1
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 1
		i += 1
	return 0

def sum_(a, n):
	d = 4
	s = n * (2 * a + (n - 1) * d) // 2
	return s

def aux(x, y):
	if x == 'a' and y == 'z':
		return 1
	if y == 'a' and x == 'z':
		return 1
	return abs(ord(x) - ord(y))

def aux1(x, y):
	if x == 'a' and y == 'z':
		return 1
	if y == 'z' and x == 'a':
		return 1
	return ord('z') - ord(y) + ord(x) - ord('a')

def find(low, high, p, ans):
	while low <= high:
		mid = (low + high) // 2
		temp = pow(mid, p)
		if temp == ans:
			return mid
		elif temp > ans:
			high = mid - 1
		else:
			low = mid + 1
	return high
for _ in range(t()):
	n = t()
	a = list(ll())
	c = a[::2]
	d = a[1::2]
	y = c[0]
	fl = 0
	for i in c:
		if gcd(i, y) == 1:
			y = 1
			break
		y = gcd(i, y)
	z = d[0]
	for i in d:
		if gcd(i, z) == 1:
			z = 1
			break
		z = gcd(i, z)
	for i in c:
		if i % z == 0:
			fl += 1
			break
	else:
		print(z)
	if fl:
		for i in d:
			if i % y == 0:
				fl += 1
				break
		else:
			print(y)
	if fl > 1:
		print(0)


import random
from collections import Counter, defaultdict
from copy import deepcopy as dc
import math
try:
	t = int(input())
	for tt in range(1, t + 1):
		n = int(input())
		a = list(map(int, input().split()))
		(gcd1, gcd2) = (a[1], a[0])
		for i in range(len(a)):
			if i % 2:
				gcd1 = math.gcd(gcd1, a[i])
			else:
				gcd2 = math.gcd(gcd2, a[i])
		if gcd1 == gcd2:
			print(0)
		else:
			(flag1, flag2) = (0, 0)
			for i in range(len(a)):
				if i % 2 and a[i] % gcd2 == 0 and (gcd2 != 1):
					flag1 = 1
				elif i % 2 == 0 and a[i] % gcd1 == 0 and (gcd1 != 1):
					flag2 = 1
			if flag1 != 0 and flag2 != 0:
				print(0)
			elif flag1 == 0 and gcd2 != 1:
				print(gcd2)
			elif flag2 == 0 and gcd1 != 1:
				print(gcd1)
			else:
				print(0)
except EOFError as e:
	pass


import math
for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	b = [0] * 3
	i = 0
	for x in a:
		b[i] = math.gcd(b[i], x)
		i ^= 1
	print(b[[*(all((x % b[i] for x in a[i ^ 1::2])) for i in (0, 1)), 1].index(1)])


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = []
	a2 = []
	for i in range(n):
		if i % 2 == 0:
			a1.append(a[i])
		else:
			a2.append(a[i])
	a1.sort()
	a2.sort()
	gcd1 = a1[0]
	gcd2 = a2[0]
	n1 = len(a1)
	n2 = len(a2)
	if n1 > 1:
		gcd1 = math.gcd(gcd1, a1[1])
	if n2 > 1:
		gcd2 = math.gcd(gcd2, a2[1])
	flag = 0
	for i in range(2, n1):
		gcd1 = math.gcd(gcd1, a1[i])
	for i in range(2, n2):
		gcd2 = math.gcd(gcd2, a2[i])
	for i in range(n1):
		if a1[i] % gcd2 == 0:
			flag = 1
			break
	if flag == 0:
		print(gcd2)
		continue
	flag = 0
	for i in range(n2):
		if a2[i] % gcd1 == 0:
			flag = 1
			break
	if flag == 0:
		print(gcd1)
	else:
		print(0)


import io, os
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, namedtuple
from heapq import heappush, heappop
from math import gcd, ceil, floor, factorial, sqrt
from itertools import combinations, permutations
input = sys.stdin.buffer.readline

def work():
	ans = 0
	return

def main():
	test = int(input())
	for idt in range(test):
		n = int(input())
		nums = list(map(int, input().split()))
		(a, b) = ([], [])
		for i in range(n):
			if i % 2 == 0:
				a.append(nums[i])
			else:
				b.append(nums[i])
		flag = False
		for i in a:
			if i in b:
				flag = True
				break
		max_gcd1 = a[0]
		for i in range(1, len(a)):
			max_gcd1 = gcd(max_gcd1, a[i])
		max_gcd2 = b[0]
		for i in range(1, len(b)):
			max_gcd2 = gcd(max_gcd2, b[i])
		ans = 0
		if max_gcd1 == max_gcd2 or flag:
			ans = 0
		else:
			flag = True
			for i in b:
				if i % max_gcd1 == 0:
					flag = False
					break
			if flag:
				ans = max_gcd1
			flag = True
			for i in a:
				if i % max_gcd2 == 0:
					flag = False
					break
			if flag:
				ans = max_gcd2
		print(ans)
	return
main()


import math
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b1 = []
	b2 = []
	for i in range(n):
		if i % 2 == 0:
			b1.append(a[i])
		else:
			b2.append(a[i])
	d1 = reduce(math.gcd, b1)
	d2 = reduce(math.gcd, b2)
	flag_d1 = 0
	flag_d2 = 0
	if d1 == 1 and d2 == 1:
		print(0)
		continue
	for i in range(n):
		if i % 2 == 0:
			if a[i] % d2 == 0:
				flag_d2 = 1
		elif a[i] % d1 == 0:
			flag_d1 = 1
	if flag_d1 == 0:
		print(d1)
	elif flag_d2 == 0:
		print(d2)
	else:
		print(0)


def NOD(a, b):
	if a == b or b == 0:
		return a
	else:
		return NOD(b, a % b)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	w = a[0]
	q = a[1]
	e = 0
	t = 0
	for j in range(0, n, 2):
		w = NOD(w, a[j])
	for j in range(1, n, 2):
		if w <= a[j]:
			if a[j] % w == 0:
				e = -1
		q = NOD(q, a[j])
	for j in range(0, n, 2):
		if q <= a[j]:
			if a[j] % q == 0:
				t = -1
				break
	if w == 1:
		e = -1
	if q == 1:
		t = -1
	if t != -1:
		print(q)
	elif e != -1:
		print(w)
	else:
		print(0)


from math import gcd

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	a = arr[0]
	for i in range(2, len(arr), 2):
		a = gcd(a, arr[i])
	b = arr[1]
	for j in range(3, len(arr), 2):
		b = gcd(b, arr[j])
	res_a = True
	res_b = True
	for i in range(0, n, 2):
		res_b = res_b and arr[i] % b != 0
	for i in range(1, n, 2):
		res_a = res_a and arr[i] % a != 0
	ans = 0
	if res_b:
		ans = max(ans, b)
	if res_a:
		ans = max(ans, a)
	print(ans)
t = int(input())
while t:
	t -= 1
	solve()


from math import gcd
from functools import reduce
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	evens = [b for (i, b) in enumerate(a) if i % 2 == 0]
	odds = [b for (i, b) in enumerate(a) if i % 2 == 1]
	go = reduce(gcd, odds)
	ge = reduce(gcd, evens)
	(fo, fe) = (False, False)
	for odd in odds:
		if odd % ge == 0:
			fo = True
			break
	for even in evens:
		if even % go == 0:
			fe = True
			break
	if not fo and (not fe):
		print(go)
	elif not fo:
		print(ge)
	elif not fe:
		print(go)
	else:
		print(0)


def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	gcd1 = b[0]
	gcd2 = b[1]
	for j in range(n):
		if j % 2 == 0:
			gcd1 = find_gcd(gcd1, b[j])
		else:
			gcd2 = find_gcd(gcd2, b[j])
	if gcd1 == 1 and gcd2 == 1:
		print(0)
		continue
	f = 0
	for j in range(n):
		if j % 2 == 1:
			if b[j] % gcd1 == 0:
				f = 1
				break
	if f == 0:
		print(gcd1)
		continue
	f = 0
	for j in range(n):
		if j % 2 == 0:
			if b[j] % gcd2 == 0:
				f = 1
				break
	if f == 0:
		print(gcd2)
	else:
		print(0)


from collections import defaultdict
from math import gcd
from os import path, truncate
from sys import int_info, stdin, stdout
if path.exists('tc.txt'):
	stdin = open('tc.txt', 'r')

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

def gms():
	return map(str, stdin.readline().strip().split())

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

def gart():
	return tuple(map(int, stdin.readline().strip().split()))

def gars():
	return list(map(str, stdin.readline().strip().split()))

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

def gls():
	return list(stdin.readline().strip())

def gi():
	return int(stdin.readline())
for _ in range(gi()):
	n = int(input())
	l = list(map(int, input().split()))
	f = l[::2]
	s = l[1::2]
	f.sort()
	s.sort()
	gf = f[0]
	gs = s[0]
	for i in range(len(f)):
		gf = gcd(gf, f[i])
		if gf == 1:
			break
	for i in range(len(s)):
		gs = gcd(gs, s[i])
		if gs == 1:
			break
	if gf == gs:
		print(0)
		continue
	if gf > 1:
		for i in s:
			if i % gf == 0:
				gf = 1
				break
	if gs > 1:
		for i in f:
			if i % gs == 0:
				gs = 1
				break
	if gf == gs:
		print(0)
	else:
		print(max(gf, gs))


import os
import sys
from io import BytesIO, IOBase
import math
mod = 1000000007

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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 * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

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 lower_bound(arr, n, k):
	start = 0
	end = n - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == k:
			return mid
		elif arr[mid] > k:
			if mid > 0:
				if arr[mid - 1] < k:
					return mid - 1
			else:
				return -1
		elif mid < n - 1:
			if arr[mid + 1] > k:
				return mid
		else:
			return mid

def upper_bound(arr, n, k):
	start = 0
	end = n - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == k:
			return mid
		elif arr[mid] > k:
			if mid > 0:
				if arr[mid - 1] < k:
					return mid
			else:
				return mid
		elif mid < n - 1:
			if arr[mid + 1] > k:
				return mid + 1
		else:
			return -1

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

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

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		gcd1 = arr[0]
		for i in range(2, n, 2):
			gcd1 = gcd(gcd1, arr[i])
		gcd2 = arr[1]
		for i in range(3, n, 2):
			gcd2 = gcd(gcd2, arr[i])
		if gcd1 == gcd2:
			print(0)
			continue
		flag1 = True
		for i in range(0, n, 2):
			if arr[i] % gcd2 == 0:
				flag1 = False
				break
		flag2 = True
		for i in range(1, n, 2):
			if arr[i] % gcd1 == 0:
				flag2 = False
				break
		if flag1:
			print(gcd2)
		elif flag2:
			print(gcd1)
		else:
			print(0)
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 functools import *

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

def check(s):
	for k in range(1, len(s)):
		if s[k] == s[k - 1]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	v1 = reduce(gcd, [a[k] for k in range(0, n, 2)])
	v2 = reduce(gcd, [a[k] for k in range(1, n, 2)])
	(s1, s2) = ('', '')
	for k in range(n):
		if a[k] % v1 == 0:
			s1 += 'R'
		else:
			s1 += 'B'
		if a[k] % v2 == 0:
			s2 += 'R'
		else:
			s2 += 'B'
	if check(s1):
		print(v1)
	elif check(s2):
		print(v2)
	else:
		print(0)


import sys, collections, math, bisect, heapq, random, functools, io, os, copy
input = sys.stdin.readline
out = sys.stdout.flush

def rep():
	a = list(map(int, input().split()))
	return a

def sep():
	a = list(input().split())
	return a

class UnionFind:

	def __init__(self, x) -> None:
		self.uf = [-1] * x

	def find(self, x):
		r = x
		while self.uf[x] >= 0:
			x = self.uf[x]
		while r != x:
			(self.uf[r], r) = (x, self.uf[r])
		return x

	def union(self, x, y):
		(ux, uy) = (self.find(x), self.find(y))
		if ux == uy:
			return
		if self.uf[ux] >= self.uf[uy]:
			self.uf[uy] += self.uf[ux]
			self.uf[ux] = uy
		else:
			self.uf[ux] += self.uf[uy]
			self.uf[uy] = ux
		return

	def __print__(self):
		return self.uf

def spfa(x, g, n):
	dis = [float('inf') for i in range(n)]
	dis[x] = 0
	state = [False for i in range(n)]
	state[x] = True
	queue = collections.deque()
	queue.append(x)
	while queue:
		cur = queue.popleft()
		state[cur] = False
		for next_ in g[cur]:
			if dis[next_] > dis[cur] + 1:
				dis[next_] = dis[cur] + 1
				if state[next_] == False:
					state[next_] = True
					queue.append(next_)
	return dis

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

def solve():
	n = int(input())
	a = rep()
	if n == 2:
		if a[0] == a[1]:
			print(0)
		else:
			print(max(a))
	else:
		b1 = a[0]
		b2 = a[1]
		l = 2
		r = 3
		while r < n:
			b2 = gcd(b2, a[r])
			r += 2
		while l < n:
			b1 = gcd(b1, a[l])
			l += 2
		flag1 = 1
		l = 1
		while l < n:
			if a[l] % b1 == 0:
				flag1 = 0
				break
			l += 2
		flag2 = 1
		l = 0
		while l < n:
			if a[l] % b2 == 0:
				flag2 = 0
				break
			l += 2
		if not flag1 and (not flag2):
			print(0)
		elif flag1:
			print(b1)
		else:
			print(b2)
for i in range(int(input())):
	solve()


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

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	gcd_0 = a[0]
	gcd_1 = a[1]
	for ii in range(0, n, 2):
		gcd_0 = gcd(gcd_0, a[ii])
	for ii in range(1, n, 2):
		gcd_1 = gcd(gcd_1, a[ii])
	flg0 = True
	flg1 = True
	for ii in range(1, n, 2):
		if a[ii] % gcd_0 == 0:
			flg0 = False
			break
	for ii in range(0, n, 2):
		if a[ii] % gcd_1 == 0:
			flg1 = False
			break
	if flg0:
		ret.append(gcd_0)
	elif flg1:
		ret.append(gcd_1)
	else:
		ret.append(0)
print(*ret, sep='\n')


import sys, os
import math
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase
from heapq import *
from bisect import *
from collections import *

def main():
	for _ in range(mi()):
		x = mi()
		a = list(MI())
		if x == 1:
			print(a[0])
			continue
		eve = a[0]
		odd = a[1]
		for i in range(2, len(a)):
			if i & 1:
				odd = math.gcd(odd, a[i])
			else:
				eve = math.gcd(eve, a[i])
		if eve == odd:
			print(0)
		else:
			flag1 = 0
			for i in range(0, len(a), 2):
				if a[i] % odd == 0:
					flag1 = 1
					break
			flag2 = 0
			for i in range(1, len(a), 2):
				if a[i] % eve == 0:
					flag2 = 1
					break
			if flag1 and flag2:
				print(0)
			elif not flag2:
				print(eve)
			elif not flag1:
				print(odd)
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 MI():
	return map(int, input().split())

def mi():
	return int(input())

def outP(var):
	sys.stdout.write(str(var) + '\n')
MOD = 10 ** 9 + 7
mod = 998244353
main()


import os
import sys
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heapify, heappop, heappush, nlargest, nsmallest
from io import BytesIO, IOBase
from math import inf, sqrt
from types import GeneratorType
BUFSIZE: int = 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()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def modInverse(a, m):
	g = gcd(a, m)
	if g != 1:
		return -1
	else:
		return power(a, m - 2, m)

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

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

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
	ans = set()
	for p in range(2, n + 1):
		if prime[p]:
			ans.add(p)
	return ans
MOD = 1000000007
INT_MAX = inf
INT_MIN = -inf

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		(g1, g2) = (a[0], a[1])
		for i in range(0, n, 2):
			g1 = gcd(g1, a[i])
		for i in range(1, n, 2):
			g2 = gcd(g2, a[i])
		if g1 == 1 and g2 == 1 or g1 == g2:
			print(0)
		elif g2 > g1:
			check = False
			for i in range(0, n, 2):
				if a[i] % g2 == 0:
					check = True
					break
			if check == True:
				if g2 % g1 == 0:
					print(0)
				else:
					check = False
					for i in range(1, n, 2):
						if a[i] % g1 == 0:
							check = True
							break
					if check == True:
						print(0)
					else:
						print(g1)
			else:
				print(g2)
		else:
			check = False
			for i in range(1, n, 2):
				if a[i] % g1 == 0:
					check = True
					break
			if check == True:
				if g1 % g2 == 0:
					print(0)
				else:
					check = False
					for i in range(0, n, 2):
						if a[i] % g2 == 0:
							check = True
							break
					if check == True:
						print(0)
					else:
						print(g2)
			else:
				print(g1)
main()


from math import gcd
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	gcd1 = a[0]
	gcd2 = a[1]
	for i in range(2, n, 2):
		gcd1 = gcd(gcd1, a[i])
	for i in range(3, n, 2):
		gcd2 = gcd(gcd2, a[i])
	flag1 = True
	flag2 = True
	for i in range(n):
		if i % 2 == 0:
			if a[i] % gcd2 == 0:
				flag2 = False
		elif a[i] % gcd1 == 0:
			flag1 = False
	if flag1:
		print(gcd1)
	elif flag2:
		print(gcd2)
	else:
		print(0)


from math import gcd
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = a[0]
	y = a[1]
	for i in range(0, n, 2):
		x = gcd(x, a[i])
		if i != n - 1:
			y = gcd(y, a[i + 1])
	A = 1
	B = 1
	for i in range(0, n, 2):
		if a[i] % y == 0:
			A = 0
		if i != n - 1:
			if a[i + 1] % x == 0:
				B = 0
	if A:
		print(y)
	elif B:
		print(x)
	else:
		print(0)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
import math
import heapq
import bisect
import collections

def ceil(a, b):
	return (a + b - 1) // b
BUFSIZE = 8192
inf = float('inf')

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))
get = lambda : sys.stdin.readline().rstrip('\r\n')
MOD = 1000000007

def v():
	return list()

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for _ in range(int(get())):
	n = int(get())
	l = list(map(int, get().split()))
	g1 = l[0]
	f1 = 0
	f2 = 0
	for i in range(n):
		if i % 2 == 0:
			g1 = gcd(l[i], g1)
	for i in range(n):
		if i % 2 == 1 and l[i] % g1 == 0:
			f1 = 1
			break
	g2 = l[1]
	for i in range(n):
		if i % 2 == 1:
			g2 = gcd(l[i], g2)
	for i in range(n):
		if i % 2 == 0 and l[i] % g2 == 0:
			f2 = 1
			break
	if f1 == 0:
		print(g1)
	elif f2 == 0:
		print(g2)
	else:
		f1 = 0
		f2 = 0
		g = 2
		for i in range(n):
			if i % 2 == 0 and l[i] % 2 != 0:
				f1 = 1
				break
			if i % 2 == 1 and l[i] % 2 == 0:
				f1 = 1
				break
		for i in range(n):
			if i % 2 == 1 and l[i] % 2 != 0:
				f2 = 1
				break
			if i % 2 == 0 and l[i] % 2 == 0:
				f2 = 1
				break
		if f1 == 0:
			print(2)
		elif f2 == 0:
			print(2)
		else:
			print(0)


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	odd = a[0:n:2]
	even = a[1:n:2]
	oddGcd = odd[0]
	for i in odd:
		oddGcd = math.gcd(oddGcd, i)
	evenGcd = even[0]
	for i in even:
		evenGcd = math.gcd(evenGcd, i)
	check = False
	for i in odd:
		if i % evenGcd == 0:
			check = True
			break
	if check != True:
		print(evenGcd)
		return
	check = False
	for i in even:
		if i % oddGcd == 0:
			check = True
			break
	if check != True:
		print(oddGcd)
		return
	print(0)
for _ in range(int(input())):
	solve()


from math import gcd

def solve():
	n = int(input())
	nums = list(map(int, input().split()))
	(gcd1, gcd2) = (0, 0)
	for i in range(0, n, 2):
		gcd1 = gcd(gcd1, nums[i])
	for i in range(1, n, 2):
		gcd2 = gcd(gcd2, nums[i])
	(c, d) = (1, 1)
	for i in range(1, n, 2):
		if nums[i] % gcd1 == 0:
			c = 0
			break
	for i in range(0, n, 2):
		if nums[i] % gcd2 == 0:
			d = 0
			break
	if not c and (not d):
		print(0)
	elif c:
		print(gcd1)
	else:
		print(gcd2)
t = int(input())
for _ in range(t):
	solve()


import sys

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

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

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

def get_int():
	return int(sys.stdin.readline().strip())

def get_list_strings():
	return list(map(str, sys.stdin.readline().strip().split()))

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

def solve():
	n = get_int()
	arr = get_list()
	arr1 = []
	arr2 = []
	for (i, ele) in enumerate(arr):
		if i % 2 == 0:
			arr1.append(ele)
		else:
			arr2.append(ele)
	g1 = arr1[0]
	l1 = len(arr1)
	for i in range(1, l1):
		g1 = gcd(g1, arr1[i])
	g2 = arr2[0]
	l2 = len(arr2)
	for i in range(1, l2):
		g2 = gcd(g2, arr2[i])
	if g1 == 1 and g2 == 1:
		print(0)
		return
	if g1 != 1:
		flag = 0
		for ele in arr2:
			if ele % g1 == 0:
				flag = 1
				break
		if flag == 0:
			print(g1)
			return
	if g2 != 1:
		flag = 0
		for ele in arr1:
			if ele % g2 == 0:
				flag = 1
				break
		if flag == 0:
			print(g2)
			return
	print(0)
T = get_int()
while T:
	solve()
	T -= 1


import math
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(odd, even) = (l[::2], l[1::2])
	(gcd1, gcd2) = (odd[0], even[0])
	for i in odd:
		gcd1 = math.gcd(gcd1, i)
	for i in even:
		gcd2 = math.gcd(gcd2, i)
	if gcd1 and all((i % gcd1 for i in even)):
		print(gcd1)
	elif gcd2 and all((i % gcd2 for i in odd)):
		print(gcd2)
	else:
		print(0)


def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(g1, g2) = (0, 0)
	for i in range(n):
		if i % 2:
			g1 = computeGCD(g1, l[i])
		else:
			g2 = computeGCD(g2, l[i])
	ans = 0
	if g1 != 1:
		f = 0
		for i in range(n):
			if i % 2 == 0 and l[i] % g1 == 0:
				f = 1
				break
		if f == 0:
			ans = g1
	if g2 != 1:
		f = 0
		for i in range(n):
			if i % 2 and l[i] % g2 == 0:
				f = 1
				break
		if f == 0:
			ans = g2
	print(ans)


import sys, math

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

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

def get_strings():
	return list(sys.stdin.readline().strip().split())

def get_num():
	return int(sys.stdin.readline().strip())
t = get_num()
for _ in range(t):
	n = get_num()
	arr = get_ints()
	d = [0, 0]
	for i in range(n):
		d[i % 2] = math.gcd(d[i % 2], arr[i])
	success = [True, True]
	for i in range(n):
		other = (i + 1) % 2
		success[other] = success[other] and arr[i] % d[other] != 0
	if success[0]:
		print(d[0])
	elif success[1]:
		print(d[1])
	else:
		print(0)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
import bisect
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
ABCD = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
months = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

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 _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	gcd = 0
	gcd_2 = 0
	for i in range(n):
		if i % 2:
			gcd = math.gcd(gcd, l[i])
		else:
			gcd_2 = math.gcd(gcd_2, l[i])
	if gcd_2 == gcd:
		print(0)
		continue
	check = True
	if gcd != 1:
		for i in range(n):
			if i % 2 == 0:
				if l[i] % gcd == 0:
					check = False
	if check and gcd != 1:
		print(gcd)
		continue
	check = True
	if gcd_2 != 1:
		for i in range(n):
			if i % 2:
				if l[i] % gcd_2 == 0:
					check = False
	if check and gcd_2 != 1:
		print(gcd_2)
		continue
	print(0)


def gcd(a, b):
	while a % b != 0:
		t = a % b
		(a, b) = (b, t)
	return b
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	sgcd = set()
	ogcd = l[0]
	egcd = l[1]
	f = 0
	for i in range(n):
		if i < n - 1:
			sgcd.add(gcd(l[i], l[i + 1]))
		if i % 2 == 0:
			ogcd = gcd(ogcd, l[i])
		else:
			egcd = gcd(egcd, l[i])
	if ogcd != 1 and ogcd not in sgcd:
		for i in range(1, n, 2):
			if l[i] % ogcd == 0:
				ogcd = 0
				break
		if ogcd != 0:
			print(ogcd)
			continue
	if egcd != 1 and egcd not in sgcd:
		for i in range(0, n, 2):
			if l[i] % egcd == 0:
				egcd = 0
				break
		if egcd != 0:
			print(egcd)
			continue
	print(0)


from math import gcd
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	evens = arr[0]
	odds = arr[1]
	for i in range(2, n, 2):
		evens = gcd(evens, arr[i])
	for i in range(1, n, 2):
		odds = gcd(odds, arr[i])
	evens = 0 if any((num % evens == 0 for num in arr[1::2])) else evens
	if any((num % odds == 0 for num in arr[::2])):
		odds = 0
	print(max(odds, evens))


from math import gcd

def r(a):
	p = a[0]
	for i in a:
		p = gcd(p, i)
	return p
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	for i in range(0, n, 2):
		b.append(a[i])
	for j in range(1, n, 2):
		c.append(a[j])
	(rb, rc) = (r(b), r(c))
	a1 = []
	b1 = []
	for i in range(n):
		a1.append(a[i] % rb)
		b1.append(a[i] % rc)
	(f1, f2) = (True, True)
	for i in range(n - 1):
		if a1[i] == 0 and a1[i + 1] == 0 or (a1[i] != 0 and a1[i + 1] != 0):
			f1 = False
		if b1[i] == 0 and b1[i + 1] == 0 or (b1[i] != 0 and b1[i + 1] != 0):
			f2 = False
	if f1:
		print(rb)
	elif f2:
		print(rc)
	else:
		print(0)


import math

def solve(n, arr):
	d = arr[0]
	p = True
	for j in range(0, n, 2):
		d = math.gcd(d, arr[j])
	for j in range(1, n, 2):
		if arr[j] % d == 0:
			p = False
	if p:
		return d
	d = arr[1]
	for j in range(1, n, 2):
		d = math.gcd(d, arr[j])
	for j in range(0, n, 2):
		if arr[j] % d == 0:
			return 0
	return d
t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	print(solve(n, arr))


import sys
input = sys.stdin.readline
from math import gcd
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	a = w[::2]
	b = w[1::2]
	x = reduce(gcd, a)
	y = reduce(gcd, b)
	if y != 0 and all((i % y != 0 for i in a)):
		print(y)
	elif x != 0 and all((i % x != 0 for i in b)):
		print(x)
	else:
		print(0)


def factorisation(a):
	ans = []
	for i in range(2, int(a ** 0.5 + 1)):
		if a % i == 0:
			ans.append(i)
	return ans

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

def check(d, a):
	mode = 1
	if a[0] % d == 0:
		mode = 0
	for i in range(1, len(a)):
		if mode == 1 and a[i] % d != 0:
			return False
		elif mode == 0 and a[i] % d == 0:
			return False
		mode += 1
		mode %= 2
	return True
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = a[0]
	for i in range(2, n, 2):
		f = gcd(f, a[i])
	s = a[1]
	for i in range(3, n, 2):
		s = gcd(s, a[i])
	if check(f, a):
		print(f)
	elif check(s, a):
		print(s)
	else:
		print(0)


import sys
import bisect
import math
from collections import deque
input = lambda : sys.stdin.readline().strip()
mod = 10 ** 9 + 7

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(even, odd) = (a[0], a[1])
	for i in range(2, n):
		if i % 2 == 0:
			even = math.gcd(even, a[i])
		else:
			odd = math.gcd(odd, a[i])
	for i in range(0, n, 2):
		if a[i] % odd == 0:
			break
	else:
		return odd
	for i in range(1, n, 2):
		if a[i] % even == 0:
			break
	else:
		return even
	return 0
t = 1
t = int(input())
for _ in range(t):
	print(solve())


import math

def Solve():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 2:
		if a[0] != a[1]:
			print(max(a))
		else:
			print(0)
	else:
		u_b = a[0]
		u_c = a[1]
		for i in range(2, len(a), 2):
			u_b = math.gcd(u_b, a[i])
		for j in range(3, len(a), 2):
			u_c = math.gcd(u_c, a[j])
		if u_b == 1 and u_c == 1:
			print(0)
		else:
			k = 0
			if u_b != 1:
				r = 0
				for i in range(1, len(a), 2):
					if a[i] % u_b == 0:
						r = r + 1
				if r == 0:
					print(u_b)
					k = 1
			if k == 0 and u_c != 1:
				r = 0
				for i in range(0, len(a), 2):
					if a[i] % u_c == 0:
						r = r + 1
				if r == 0:
					print(u_c)
					k = 1
			if k == 0:
				print(0)
q = int(input())
while q > 0:
	Solve()
	q = q - 1


from math import gcd
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	l1 = l[0::2]
	l2 = l[1::2]
	g1 = l1[0]
	g2 = l2[0]
	for i in l1[1:]:
		g1 = int(gcd(g1, i))
	for j in l2[1:]:
		g2 = int(gcd(g2, j))
	if g1 == g2:
		print(0)
	else:
		for k in l2:
			if k % g1 == 0:
				a1 = 0
				break
		else:
			a1 = g1
		for k in l1:
			if k % g2 == 0:
				a2 = 0
				break
		else:
			a2 = g2
		if a1 == 0:
			if a2 == 0:
				print(0)
			else:
				print(a2)
		else:
			print(a1)


import math

def gcd(a):
	x = 0
	for p in a:
		x = math.gcd(x, p)
	return x
t = int(input())
for test_case in range(t):
	n = int(input())
	list_case = list(map(int, input().split()))
	even_elements = []
	odd_elements = []
	for index in range(0, n, 2):
		even_elements.append(list_case[index])
	for index in range(1, n, 2):
		odd_elements.append(list_case[index])
	gcd_even = gcd(even_elements)
	gcd_odd = gcd(odd_elements)
	run_even = True
	run_odd = True
	for i in range(len(odd_elements)):
		if odd_elements[i] % gcd_even == 0:
			run_even = False
			break
	for i in range(len(even_elements)):
		if even_elements[i] % gcd_odd == 0:
			run_odd = False
			break
	if run_even:
		print(gcd_even)
	elif run_odd:
		print(gcd_odd)
	else:
		print(0)


from collections import Counter, defaultdict
import math
import bisect

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

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

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

def main():
	t = int(input())
	for num in range(t):
		n = int(input())
		arr = getlist()
		gcd1 = arr[0]
		gcd2 = arr[1]
		for (i, numbers) in enumerate(arr):
			if i % 2 == 0:
				gcd1 = compute_gcd(gcd1, numbers)
			else:
				gcd2 = compute_gcd(gcd2, numbers)
		i = 1
		flag = True
		while i < n and gcd1 > 1:
			if arr[i] % gcd1 == 0:
				flag = False
				break
			i += 2
		if flag is True and gcd1 > 1:
			print(gcd1)
		else:
			i = 0
			flag1 = True
			while i < n and gcd2 > 1:
				if arr[i] % gcd2 == 0:
					flag1 = False
					break
				i += 2
			if flag1 is True and gcd2 > 1:
				print(gcd2)
			else:
				print(0)
main()


import sys
from math import gcd
input = sys.stdin.readline

def lcm(li):
	f = li[0]
	for i in li[1:]:
		f = f * i // gcd(f, i)
	return f
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	g1 = a[0]
	for i in a[::2]:
		g1 = gcd(g1, i)
	g2 = a[1]
	for i in a[1::2]:
		if i % g1 == 0:
			g1 //= gcd(g1, i)
		g2 = gcd(g2, i)
	for i in a[::2]:
		if i % g2 == 0:
			g2 //= gcd(g2, i)
	if g1 != 1:
		print(g1)
	elif g2 != 1:
		print(g2)
	else:
		print(0)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for q in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = 0
	gcd1 = arr[0]
	gcd2 = arr[1]
	for i in range(2, n, 2):
		gcd1 = gcd(gcd1, arr[i])
	for i in range(3, n, 2):
		gcd2 = gcd(gcd2, arr[i])
	flag = -1
	if gcd1 != 1:
		d = gcd1
		flag = 1
		while flag < n:
			if arr[flag] % gcd1 == 0:
				d = 0
				break
			flag += 2
	if gcd2 != 1 and d == 0:
		d = gcd2
		flag = 0
		while flag < n:
			if arr[flag] % gcd2 == 0:
				d = 0
				break
			flag += 2
	print(d)


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	(b, c) = ([], [])
	for j in range(n):
		if j % 2 == 0:
			b.append(a[j])
		else:
			c.append(a[j])
	p = True
	q = True
	x = b[0]
	y = c[0]
	for j in range(1, len(b)):
		if b[j] == 1:
			p = False
			break
		x = hcfnaive(x, b[j])
		if x == 1:
			p = False
			break
	for j in range(1, len(c)):
		if c[j] == 1:
			q = False
			break
		y = hcfnaive(y, c[j])
		if y == 1:
			q = False
			break
	(r, u) = (True, True)
	if p == True:
		for j in range(len(c)):
			if c[j] % x == 0:
				r = False
				break
	if q == True:
		for j in range(len(b)):
			if b[j] % y == 0:
				u = False
				break
	if p == True and r == True:
		print(x)
	elif q == True and u == True:
		print(y)
	else:
		print(0)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
for _ in range(int(input())):
	n = int(input())
	a = inp()
	ko = a[1]
	ke = a[0]
	for i in range(n):
		if i % 2:
			ko = gcd(ko, a[i])
		else:
			ke = gcd(ke, a[i])
	flag = True
	for i in range(n):
		if a[i] % ko:
			if i % 2:
				flag = False
				break
		elif i % 2 == 0:
			flag = False
			break
	if flag:
		print(ko)
		continue
	flag = True
	for i in range(n):
		if a[i] % ke:
			if i % 2 == 0:
				flag = False
				break
		elif i % 2:
			flag = False
			break
	if flag:
		print(ke)
		continue
	print(0)


from math import gcd
from functools import reduce
n = int(input())
while n != 0:
	(val1, val2) = (0, 0)
	x = int(input())
	lst = list(map(int, input().split()))
	lst1 = lst[::2]
	lst2 = lst[1::2]
	gcd1 = reduce(gcd, lst1)
	gcd2 = reduce(gcd, lst2)
	if gcd1 == gcd2:
		print(0)
		n -= 1
		continue
	for l in lst1:
		if l % gcd2 == 0:
			val1 = 1
			break
	if val1 == 0:
		print(gcd2)
		n -= 1
		continue
	for m in lst2:
		if m % gcd1 == 0:
			val2 = 1
			break
	if val2 == 0:
		print(gcd1)
		n -= 1
		continue
	if val1 == 1 and val2 == 1:
		print(0)
	n -= 1


import sys
from math import gcd

def gcdGeneral(numbers):
	if len(numbers) == 0:
		return 1
	if len(numbers) == 1:
		return numbers[0]
	else:
		curr = gcd(numbers[0], numbers[1])
		for i in range(2, len(numbers)):
			curr = gcd(curr, numbers[i])
	return curr

def parseInput():
	rawInput = sys.stdin.read().split('\n')
	rawInput = rawInput[1:-1]
	inputs = rawInput[1::2]
	return inputs

def findD(numbers):
	numbers = numbers.split()
	for i in range(len(numbers)):
		numbers[i] = int(numbers[i])
	half1 = numbers[::2]
	half2 = numbers[1::2]
	d1 = gcdGeneral(half1)
	d2 = gcdGeneral(half2)
	works = d1 != 1
	if works:
		for n in half2:
			if n % d1 == 0:
				works = False
				break
	if works:
		return d1
	works = d2 != 1
	if works:
		for n in half1:
			if n % d2 == 0:
				works = False
				break
	if works:
		return d2
	return 0
for numbers in parseInput():
	print(findD(numbers))


def gcd(a, b):
	if a == b:
		return a
	elif a > b:
		(a, b) = (b, a)
	while a > 0:
		(a, b) = (b % a, a)
	return b
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	if n == 2:
		if x[0] == x[1]:
			print(0)
		else:
			print(max(x))
	elif n == 3:
		g = gcd(x[0], x[2])
		if x[1] % g > 0:
			print(g)
		elif x[0] % x[1] > 0 and x[2] % x[1] > 0:
			print(x[1])
		else:
			print(0)
	else:
		g1 = gcd(x[0], x[2])
		g2 = gcd(x[1], x[3])
		m1 = max(x[0], x[2])
		m2 = max(x[1], x[3])
		for i in range(4, n):
			if i % 2 == 0:
				if g1 > 1:
					g1 = gcd(g1, x[i])
				m1 = max(m1, x[i])
			if i % 2 == 1:
				if g2 > 1:
					g2 = gcd(g2, x[i])
				m2 = max(m2, x[i])
		if g1 == 1 and g2 == 1:
			print(0)
		elif g1 == 1 and g2 > 1:
			if m1 < g2:
				ans = g2
			elif m1 == g2:
				ans = 0
			elif m1 > g2:
				ans = g2
				for i in range(0, n, 2):
					if x[i] % g2 == 0:
						ans = 0
						break
			print(ans)
		elif g1 > 1 and g2 == 1:
			if m2 < g1:
				ans = g1
			elif m2 == g1:
				ans = 0
			elif m2 > g1:
				ans = g1
				for i in range(1, n, 2):
					if x[i] % g1 == 0:
						ans = 0
						break
			print(ans)
		elif g1 > 1 and g2 > 1:
			if m1 < g2:
				ans = g2
			elif m2 < g1:
				ans = g1
			elif m1 == g2:
				ans = 0
			elif m2 == g1:
				ans = 0
			else:
				ans = g1
				for i in range(1, n, 2):
					if x[i] % g1 == 0:
						ans = 0
						break
				if ans == 0:
					ans = g2
					for i in range(0, n, 2):
						if x[i] % g2 == 0:
							ans = 0
							break
			print(ans)


import sys
import os
from math import ceil, floor, sqrt, gcd, factorial, log, log2
from io import BytesIO, IOBase
from collections import Counter, deque
from bisect import bisect
inf = int(10000000000.0)
BUFSIZE = 8192
inp = lambda : int(input())
mp = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))

def main():
	for _ in range(inp()):
		n = inp()
		a = lst()
		u = 0
		v = 0
		m1 = 1e+21
		m2 = 1e+21
		for i in range(0, n, 2):
			if u == 0:
				u = a[i]
			else:
				u = gcd(u, a[i])
			m1 = min(m1, a[i])
		for i in range(1, n, 2):
			if v == 0:
				v = a[i]
			else:
				v = gcd(v, a[i])
			m2 = min(m2, a[i])
		fu = True
		fv = True
		for i in range(n):
			if i % 2 == 0 and a[i] % u == 0:
				continue
			elif i % 2 != 0 and a[i] % u != 0:
				continue
			else:
				fu = False
				break
		for i in range(n):
			if i % 2 == 0 and a[i] % v != 0:
				continue
			elif i % 2 != 0 and a[i] % v == 0:
				continue
			else:
				fv = False
				break
		if fu:
			print(u)
		elif fv:
			print(v)
		else:
			print(0)

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()


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	n = I()
	a = L()
	g1 = g2 = f1 = f2 = 0
	for i in range(0, n, 2):
		g1 = math.gcd(g1, a[i])
	for i in range(1, n, 2):
		g2 = math.gcd(g2, a[i])
	for i in range(0, n, 2):
		if a[i] % g2 == 0:
			f1 = 1
			break
	for i in range(1, n, 2):
		if a[i] % g1 == 0:
			f2 = 1
			break
	if f1 == 0:
		print(g2)
	elif f2 == 0:
		print(g1)
	else:
		print(0)


import sys
import math
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	gcd1 = arr[0]
	gcd2 = arr[1]
	for i in range(0, n, 2):
		gcd1 = math.gcd(gcd1, arr[i])
	for i in range(1, n, 2):
		gcd2 = math.gcd(gcd2, arr[i])
	chk = False
	for i in range(1, n, 2):
		if arr[i] % gcd1 == 0:
			chk = True
	if not chk:
		print(gcd1)
	else:
		chk = False
		for i in range(0, n, 2):
			if arr[i] % gcd2 == 0:
				chk = True
		if not chk:
			print(gcd2)
		else:
			print(0)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 2:
		if a[0] != a[1]:
			print(max(a))
		else:
			print(0)
	else:
		gcd1 = a[0]
		for i in range(2, n, 2):
			gcd1 = math.gcd(gcd1, a[i])
		gcd2 = a[1]
		for i in range(3, n, 2):
			gcd2 = math.gcd(gcd2, a[i])
		if gcd1 == 1 and gcd2 == 1:
			print(0)
		elif gcd1 == 1:
			flag = 0
			for i in range(0, n, 2):
				if a[i] % gcd2 == 0:
					flag = 1
					break
			if flag:
				print(0)
			else:
				print(gcd2)
		elif gcd2 == 1:
			flag = 0
			for i in range(1, n, 2):
				if a[i] % gcd1 == 0:
					flag = 1
					break
			if flag:
				print(0)
			else:
				print(gcd1)
		else:
			flag = 0
			flag2 = 0
			for i in range(n):
				if i % 2 == 0:
					if a[i] % gcd2 == 0:
						flag = 1
						break
			if flag:
				for i in range(n):
					if i % 2:
						if a[i] % gcd1 == 0:
							flag2 = 1
							break
			if flag and flag2:
				print(0)
			elif flag and (not flag2):
				print(gcd1)
			else:
				print(gcd2)


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

def func():
	n = int(input())
	a = list(map(int, input().split()))
	g1 = 0
	v = 2
	for i in range(0, n, 2):
		g1 = gcd(a[i], g1)
	g2 = 0
	for i in range(1, n, 2):
		g2 = gcd(a[i], g2)
		if a[i] % g1 == 0 and v == 2:
			v = 1
	if v == 2:
		print(g1)
		return
	for i in range(0, n, 2):
		if a[i] % g2 == 0 and v == 1:
			print(0)
			return
	print(g2)
	return
t = int(input())
for i in range(t):
	func()


from math import gcd
from functools import reduce
t = int(input())
for j in range(t):
	n = int(input())
	mas = list(map(int, input().split()))
	k = []
	s = []
	for i in range(n):
		if i % 2 == 0:
			k.append(mas[i])
		else:
			s.append(mas[i])
	k.sort()
	s.sort()
	a = reduce(gcd, k)
	b = reduce(gcd, s)
	aa = True
	bb = True
	for i in k:
		if i % a != 0:
			aa = False
		if i % b == 0:
			bb = False
	for i in s:
		if i % b != 0:
			bb = False
		if i % a == 0:
			aa = False
	if aa:
		print(a)
	elif bb:
		print(b)
	else:
		print(0)


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

def gcd(l):
	if len(l) == 1:
		return l[0]
	num1 = l[0]
	num2 = l[1]
	gcd = find_gcd(num1, num2)
	for i in range(2, len(l)):
		gcd = find_gcd(gcd, l[i])
	return gcd

def func(arr, N):
	ev = [arr[i] for i in range(N) if i % 2 == 0]
	od = [arr[i] for i in range(N) if i % 2]
	gcd1 = gcd(ev)
	gcd2 = gcd(od)
	(ans1, ans2) = (True, True)
	for i in ev:
		if i % gcd2 == 0:
			ans1 = False
			break
	if ans1:
		return gcd2
	for i in od:
		if i % gcd1 == 0:
			ans2 = False
			break
	if ans2:
		return gcd1
	return 0
for t in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	print(func(arr, N))


def get_gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(a) == 2:
		if a[0] == a[1]:
			print(0)
		else:
			print(max(a))
		continue
	a1 = a[::2]
	a2 = a[1::2]
	a1.sort()
	a2.sort()
	count1 = 0
	count2 = 0
	gcd1 = get_gcd(a1[0], a1[1])
	if len(a2) >= 2:
		gcd2 = get_gcd(a2[0], a2[1])
	else:
		gcd2 = a2[0]
	for i in range(2, len(a1)):
		gcd1 = get_gcd(gcd1, a1[i])
	for j in range(2, len(a2)):
		gcd2 = get_gcd(gcd2, a2[j])
	for l in a1:
		if l % gcd2 == 0:
			count1 = 1
			break
	if count1 == 0:
		print(gcd2)
		continue
	else:
		for k in a2:
			if k % gcd1 == 0:
				count2 = 1
				break
		if count2 == 0:
			print(gcd1)
			continue
	if count1 == 1 and count2 == 1:
		print(0)


import math
for _ in range(int(input())):
	n = input()
	x = list(map(int, input().split(' ')))
	evens = x[::2]
	odds = x[1::2]
	g1 = x[0]
	g2 = x[1]
	for i in evens:
		if g1 != i:
			g1 = math.gcd(g1, i)
	for i in odds:
		if g2 != i:
			g2 = math.gcd(g2, i)
	for i in odds:
		if i % g1 == 0:
			g1 = 0
			break
	for i in evens:
		if i % g2 == 0:
			g2 = 0
			break
	print(max(g1, g2))


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 collections import Counter, defaultdict
import math

def nck(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
mod = 10 ** 9 + 7

def printDivisors(n):
	list = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				print(i, end=' ')
			else:
				print(i, end=' ')
				list.append(int(n / i))
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = 0
	for i in range(0, n, 2):
		s = math.gcd(s, arr[i])
	f = 0
	for i in range(1, n, 2):
		if s > 0 and arr[i] % s == 0:
			f = 1
	if f == 0:
		print(s)
	else:
		ss = 0
		for i in range(1, n, 2):
			ss = math.gcd(ss, arr[i])
		f = 0
		for i in range(0, n, 2):
			if ss > 0 and arr[i] % ss == 0:
				f = 1
		if f == 0:
			print(ss)
		else:
			print(0)


from functools import reduce
from math import gcd
t = int(input())

def getgcd(list):
	return reduce(gcd, list)

def paint(arr):
	a = arr[::2]
	b = arr[1::2]
	x = getgcd(a)
	for i in b:
		if i % x == 0:
			break
	else:
		return x
	x = getgcd(b)
	for i in a:
		if i % x == 0:
			break
	else:
		return x
	return 0
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	if len(set(arr)) > 1:
		if len(arr) > 2:
			print(paint(arr))
		else:
			print(max(arr))
	else:
		print(0)


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

def findHCF(l):
	if len(l) == 1:
		return l[0]
	hcf = find_hcf(l[0], l[1])
	for i in range(2, len(l)):
		hcf = find_hcf(hcf, l[i])
	return hcf
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(l[0])
	else:
		a1 = []
		a2 = []
		for i in range(len(l)):
			if i % 2 == 0:
				a2.append(l[i])
			else:
				a1.append(l[i])
		d1 = findHCF(a1)
		d2 = findHCF(a2)
		check1 = True
		check2 = True
		if d1 != 0:
			for i in a2:
				if i % d1 == 0:
					check1 = False
					break
		if d2 != 0:
			for i in a1:
				if i % d2 == 0:
					check2 = False
					break
		if check1 or check2:
			if check1:
				print(d1)
			else:
				print(d2)
		else:
			print(0)


import math

def gcd_many(s):
	g = 0
	for i in range(len(s)):
		if i == 0:
			g = s[i]
		else:
			g = math.gcd(g, s[i])
	return g
mm = int(input())
for i in range(mm):
	le = int(input())
	lst = list(map(int, input().split()))
	ou = lst[1:len(lst):2]
	ji = lst[0:len(lst):2]
	a = gcd_many(ji)
	flag = 0
	for l in ou:
		if l % a == 0:
			flag = 1
			break
	if flag == 0:
		print(a)
	else:
		b = gcd_many(ou)
		for l in ji:
			if l % b == 0:
				flag = 0
				break
		if flag == 1:
			print(b)
		else:
			print(0)


t = int(input())
import math
from functools import reduce
from math import gcd
for s in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	X = []
	Y = []
	for j in range(n):
		if j % 2 == 0:
			X.append(A[j])
		else:
			Y.append(A[j])
	a = reduce(gcd, X)
	b = reduce(gcd, Y)
	ok1 = True
	ok2 = True
	for i in range(n):
		if i % 2 == 1:
			if A[i] % a != 0:
				continue
			else:
				ok1 = False
		if i % 2 == 0:
			if A[i] % b != 0:
				continue
			else:
				ok2 = False
	if ok1 == True:
		print(a)
	elif ok2 == True:
		print(b)
	else:
		print(0)


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	gcd1 = l[0]
	gcd2 = l[1]
	for i in range(2, n):
		if i % 2 == 0:
			gcd1 = gcd(gcd1, l[i])
		else:
			gcd2 = gcd(gcd2, l[i])
	flag1 = 0
	flag2 = 0
	for i in range(n):
		if not flag2 and i % 2 == 0 and (l[i] % gcd2 == 0):
			flag2 = 1
		if not flag1 and i % 2 and (l[i] % gcd1 == 0):
			flag1 = 1
	if not flag1:
		print(gcd1)
	elif not flag2:
		print(gcd2)
	else:
		print(0)


import math

def niceArray(arr, l, d):
	prev = 2
	for i in arr:
		v = i % d == 0
		if prev == v:
			return False
		prev = v
	return True
cases = int(input())
for c in range(cases):
	l = int(input())
	nmbrs = list(map(int, input().split()))
	check1 = nmbrs[0]
	for i in range(2, l, 2):
		check1 = math.gcd(check1, nmbrs[i])
	if niceArray(nmbrs, l, check1):
		print(check1)
		continue
	check2 = nmbrs[1]
	for i in range(3, l, 2):
		check2 = math.gcd(check2, nmbrs[i])
	if niceArray(nmbrs, l, check2):
		print(check2)
		continue
	print(0)


import math
x = int(input())
for i in range(x):
	a = int(input())
	c = input().split()
	even1 = []
	odd1 = []
	for j in range(a):
		c[j] = int(c[j])
		if j & 1 == 0:
			even1.append(c[j])
		else:
			odd1.append(c[j])
	even1.sort()
	odd1.sort()
	gcd1 = even1[0]
	gcd2 = odd1[0]
	for kk in range(len(even1)):
		gcd1 = math.gcd(even1[kk], gcd1)
	for ll in range(len(odd1)):
		gcd2 = math.gcd(odd1[ll], gcd2)
	flag = True
	ans = gcd1
	if gcd1 == gcd2:
		print(0)
	else:
		for mm in odd1:
			if mm % gcd1 == 0:
				ans = gcd2
				flag = False
				break
		for gg in even1:
			if gg % gcd2 == 0:
				if ans == gcd2:
					ans = 0
				else:
					ans = gcd1
				break
		print(ans)


from sys import stdin, stdout

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(stdin.readline())
for tt in range(t):
	n = int(stdin.readline())
	a = [int(s) for s in stdin.readline().split()]
	(gcd0, gcd1) = (0, 0)
	success = True
	for i in range(0, n, 2):
		gcd0 = gcd(gcd0, a[i])
	for i in range(1, n, 2):
		if a[i] % gcd0 == 0:
			success = False
			break
	if success:
		stdout.write(str(gcd0) + '\n')
		continue
	success = True
	for i in range(1, n, 2):
		gcd1 = gcd(gcd1, a[i])
	for i in range(0, n, 2):
		if a[i] % gcd1 == 0:
			success = False
			break
	stdout.write(str(gcd1 if success else 0) + '\n')


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
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')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	odd = 0
	for j in range(0, n, 2):
		even = math.gcd(even, a[j])
	for j in range(1, n, 2):
		if a[j] % even == 0:
			break
	else:
		print(even)
		continue
	for j in range(1, n, 2):
		odd = math.gcd(odd, a[j])
	for j in range(0, n, 2):
		if a[j] % odd == 0:
			print(0)
			break
	else:
		print(odd)


from math import gcd

def gcdd(lst):
	if len(lst) < 2:
		return lst[0]
	g = lst[0]
	for i in range(1, len(lst)):
		g = gcd(g, lst[i])
	return g

def odder(lst):
	for i in lst:
		if i % 2 == 0:
			return False
	return True

def ever(lst):
	for i in lst:
		if i % 2 != 0:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	lst = [int(x) for x in input().split()]
	lst1 = [lst[x] for x in range(n) if x % 2 == 0]
	lst2 = [lst[x] for x in range(n) if x % 2 != 0]
	gcd1 = gcdd(lst1)
	gcd2 = gcdd(lst2)
	if all((x % gcd1 != 0 for x in lst2)):
		ans = gcd1
	elif all((x % gcd2 != 0 for x in lst1)):
		ans = gcd2
	else:
		ans = 0
	print(ans)


def gcd(a, b):
	while a * b != 0:
		(a, b) = (b, a % b)
	return a + b

def gcd_for_line(data: list):
	m_list = data.copy()
	while len(m_list) > 1:
		m_list[0] = gcd(m_list[0], m_list[1])
		m_list.pop(1)
	return m_list[0]
for i in range(int(input())):
	n = int(input())
	line = list(map(int, input().split()))
	gcd_line = list()
	honest_ind_line = list()
	for j in range(len(line)):
		if (j + 1) % 2 == 1:
			gcd_line.append(line[j])
		else:
			honest_ind_line.append(line[j])
	g = gcd_for_line(gcd_line)
	Flag = True
	for e in honest_ind_line:
		if e % g == 0:
			Flag = False
			break
	if Flag:
		print(g)
		continue
	d = gcd_for_line(honest_ind_line)
	Flag1 = True
	for elem in gcd_line:
		if elem % d == 0:
			Flag1 = False
	if Flag1:
		print(d)
		continue
	print(0)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 2:
		if a[0] == a[1]:
			print(0)
		else:
			print(max(a[1], a[0]))
		continue
	d = gcd(a[0], a[2])
	for i in range(4, n, 2):
		d = gcd(d, a[i])
	f = True
	for i in range(1, n, 2):
		if a[i] % d == 0:
			f = False
			break
	if f:
		print(d)
		continue
	if n > 3:
		d = gcd(a[1], a[3])
		for i in range(5, n, 2):
			d = gcd(d, a[i])
		f = True
		for i in range(0, n, 2):
			if a[i] % d == 0:
				f = False
				break
		if f:
			print(d)
			continue
	elif a[0] % a[1] != 0 and a[2] % a[1] != 0:
		print(a[1])
		continue
	print(0)


import sys
import math
from itertools import accumulate
from fractions import gcd
from functools import reduce

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

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

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

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

def ggt_l(l):
	return reduce(math.gcd, l)

def solve():
	n = int(input())
	ar = read_int_arr()
	l1 = []
	l2 = []
	for i in range(n):
		if i % 2 == 0:
			l1.append(ar[i])
		else:
			l2.append(ar[i])
	d1 = ggt_l(l1)
	d2 = ggt_l(l2)

	def works(l, x):
		for i in range(len(l) - 1):
			if l[i] % x == 0 and l[i + 1] % x == 0:
				return False
		return True
	if works(ar, d1):
		print(d1)
		return
	elif works(ar, d2):
		print(d2)
		return
	else:
		print(0)
T = int(input())
for _ in range(T):
	solve()


import sys
input = sys.stdin.readline

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

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

def mps(A):
	return [tuple(map(int, input().split())) for _ in range(A)]
import math
import bisect
import heapq
import time
from copy import copy as cc
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque

def ceil(U, V):
	return (U + V - 1) // V

def modf1(N, MOD):
	return (N - 1) % MOD + 1
inf = int(1e+18 + 20)
mod = int(1000000000.0 + 7)
from functools import reduce

def gcd(numbers):
	return reduce(math.gcd, numbers)
t = int(input())
for _ in range(t):
	n = int(input())
	a = lmp()
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			odd.append(a[i])
		else:
			even.append(a[i])
	og = gcd(odd)
	eg = gcd(even)
	ans = 0
	flag = True
	for j in even:
		if j % og == 0:
			flag = False
	if flag:
		print(og)
		continue
	flag = True
	for j in odd:
		if j % eg == 0:
			flag = False
	if flag:
		ans = eg
		print(eg)
		continue
	print(0)


import math
for _ in range(int(input())):
	l = int(input())
	a = list(map(int, input().split()))
	g1 = a[0]
	g2 = a[1]
	for i in a[::2]:
		g1 = math.gcd(g1, i)
	for i in a[1::2]:
		g2 = math.gcd(g2, i)
	if all(map(lambda x: x % g1 == 0, a[::2])) and all(map(lambda x: x % g1 != 0, a[1::2])):
		print(g1)
	elif all(map(lambda x: x % g2 == 0, a[::2])) and all(map(lambda x: x % g2 != 0, a[1::2])):
		print(g2)
	elif all(map(lambda x: x % g1 != 0, a[::2])) and all(map(lambda x: x % g1 == 0, a[1::2])):
		print(g1)
	elif all(map(lambda x: x % g2 != 0, a[::2])) and all(map(lambda x: x % g2 == 0, a[1::2])):
		print(g2)
	else:
		print(0)


from math import *
from functools import reduce
import sys
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = []
	r1 = []
	for i in range(1, len(a), 2):
		r.append(a[i])
		r1.append(a[i - 1])
	if n % 2 != 0:
		r1.append(a[n - 1])
	k1 = reduce(lambda x, y: gcd(x, y), r)
	k2 = reduce(lambda x, y: gcd(x, y), r1)
	p1 = 1
	p2 = 1
	for i in range(1, len(a), 2):
		if a[i] % k2 == 0:
			p1 = 0
		if a[i - 1] % k1 == 0:
			p2 = 0
	if n % 2 != 0:
		if a[n - 1] % k1 == 0:
			p2 = 0
	if p1 == p2 == 0:
		print(0)
	elif p1 != 0:
		print(k2)
	else:
		print(k1)


from math import gcd
T = int(input())
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	(og, eg) = (0, 0)
	for i in range(n):
		if i % 2:
			og = gcd(og, arr[i])
		else:
			eg = gcd(eg, arr[i])
	if og == eg:
		print(0)
	else:
		(at, bt) = (True, True)
		for i in range(n):
			if i % 2 == 0:
				if arr[i] % og == 0:
					at = False
			elif arr[i] % eg == 0:
				bt = False
		if at and bt:
			print(og)
		elif at:
			print(og)
		elif bt:
			print(eg)
		else:
			print(0)


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

def bootstrap(f, stack=[]):

	def fun(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return fun

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')
import math
import heapq
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	g1 = 0
	g2 = 0
	i = 0
	while i < n:
		if i % 2 == 0:
			g1 = math.gcd(g1, b[i])
		else:
			g2 = math.gcd(g2, b[i])
		i += 1
	i = 1
	poss = 1
	while i < n:
		if b[i] % g1 == 0:
			poss = 0
			break
		i += 2
	if poss:
		print(g1)
	else:
		i = 0
		poss = 1
		while i < n:
			if b[i] % g2 == 0:
				poss = 0
				break
			i += 2
		if poss:
			print(g2)
		else:
			print(0)


from math import gcd
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split()))
	l1 = l[::2]
	l2 = l[1::2]
	(a, b) = (l1[0], l2[0])
	if len(l1) > 1:
		for i in range(1, n // 2 + n % 2):
			a = gcd(l1[i], a)
			if a == 1:
				break
	if len(l2) > 1:
		for i in range(1, n // 2):
			b = gcd(l2[i], b)
			if b == 1:
				break
	if a > 1:
		for i in range(n // 2):
			if l2[i] % a == 0:
				a = 1
				break
	if b > 1:
		for i in range(n // 2 + n % 2):
			if l1[i] % b == 0:
				b = 1
				break
	if a == b:
		print(0)
	else:
		print(max(a, b))


def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	a = [s[i] for i in range(n) if i % 2 == 1]
	b = [s[i] for i in range(n) if i % 2 == 0]
	ra = a[-1]
	rb = b[-1]
	for x in a:
		ra = gcd(ra, x)
	for x in b:
		rb = gcd(rb, x)
	ok = True
	for i in range(len(a)):
		if a[i] % rb == 0:
			ok = False
	if ok:
		print(rb)
		continue
	ok = True
	for i in range(len(b)):
		if b[i] % ra == 0:
			ok = False
	if ok:
		print(ra)
	else:
		print(0)


import math

def Paint_The_Array(a, n):
	even = [a[i] for i in range(0, n, 2)]
	odd = [a[i] for i in range(1, n, 2)]
	gcd_odd = odd[0]
	gcd_even = even[0]
	for e in even:
		gcd_even = math.gcd(gcd_even, e)
	poss = True
	for o in odd:
		if o % gcd_even == 0 and o != 1:
			poss = False
			break
	if poss and gcd_even != 1:
		return gcd_even
	for o in odd:
		gcd_odd = math.gcd(gcd_odd, o)
	poss = True
	for e in even:
		if e % gcd_odd == 0 and e != 1:
			poss = False
			break
	if poss and gcd_odd != 1:
		return gcd_odd
	return 0
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(Paint_The_Array(a, n))


import math

def gcd(a):
	x = 0
	for p in a:
		x = math.gcd(x, p)
	return x
for i in range(int(input())):
	n = int(input())
	A = [int(k) for k in input().split()]
	f = A[::2]
	s = A[1::2]
	F = gcd(f)
	S = gcd(s)
	if F != 0 and all((x % F != 0 for x in s)):
		print(F)
	elif S != 0 and all((x % S != 0 for x in f)):
		print(S)
	else:
		print(0)


import math
t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	(gcd1, gcd2) = (0, 0)
	for i in range(n):
		if i % 2:
			gcd1 = math.gcd(gcd1, a[i])
		else:
			gcd2 = math.gcd(gcd2, a[i])
	check = True
	for i in range(0, n, 2):
		if a[i] % gcd1 == 0:
			check = False
			break
	if check:
		print(gcd1)
		continue
	check = True
	for i in range(1, n, 2):
		if a[i] % gcd2 == 0:
			check = False
			break
	if check:
		print(gcd2)
		continue
	print(0)


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a + b
t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	g1 = a[0]
	g2 = a[1]
	for i in range(2, n):
		if i % 2 == 0:
			g1 = gcd(g1, a[i])
		else:
			g2 = gcd(g2, a[i])
	res1 = res2 = True
	for i in range(n):
		if i % 2 == 0:
			if a[i] % g2 == 0:
				res2 = False
		elif a[i] % g1 == 0:
			res1 = False
	if res1:
		print(g1)
	elif res2:
		print(g2)
	else:
		print(0)


from math import gcd

def solve(n, nums):
	gcd1 = nums[0]
	for i in range(2, n, 2):
		gcd1 = gcd(gcd1, nums[i])
	gcd2 = nums[1]
	for i in range(3, n, 2):
		gcd2 = gcd(gcd2, nums[i])
	if gcd1 == gcd2:
		return 0
	for i in range(1, n, 2):
		if nums[i] % gcd1 == 0:
			gcd1 = 1
			break
	for i in range(0, n, 2):
		if nums[i] % gcd2 == 0:
			gcd2 = 1
			break
	if gcd1 == gcd2:
		return 0
	return gcd2 if gcd2 != 1 else gcd1
ans = []
for _ in range(int(input())):
	ans.append(solve(int(input()), list(map(int, input().split()))))
print(*ans, sep='\n')


t = int(input())

def gcd(my_list):
	result = my_list[0]
	for x in my_list[1:]:
		if result < x:
			temp = result
			result = x
			x = temp
		while x != 0:
			temp = x
			x = result % x
			result = temp
	return result
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	(l1, l2) = ([], [])
	for i in range(n):
		if i % 2 == 0:
			l2.append(a[i])
		else:
			l1.append(a[i])
	gcd1 = gcd(l1)
	gcd2 = gcd(l2)
	(ret1, ret2) = (True, True)
	for num in l1:
		if num % gcd2 == 0:
			ret1 = False
			break
	for num in l2:
		if num % gcd1 == 0:
			ret2 = False
			break
	if ret1 == True:
		print(gcd2)
	elif ret2 == True:
		print(gcd1)
	else:
		print(0)


import math
from functools import reduce
for j in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	le = [ls[i] for i in range(0, n, 2)]
	la = [ls[i] for i in range(1, n, 2)]
	gcd0 = reduce(lambda x, y: math.gcd(x, y), le)
	gcd1 = reduce(lambda x, y: math.gcd(x, y), la)
	gcd = 0
	if not gcd and all((i % gcd0 for i in la)):
		gcd = gcd0
	if not gcd and all((i % gcd1 for i in le)):
		gcd = gcd1
	print(gcd)


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	od = sorted([d[i] for i in range(0, n, 2)])
	ed = sorted([d[i] for i in range(1, n, 2)])
	res = True
	g = od[0]
	for i in od:
		g = math.gcd(g, i)
	for i in ed:
		if i % g == 0:
			res = False
			break
	if not res:
		res = True
		g = ed[0]
		for i in ed:
			g = math.gcd(g, i)
		for i in od:
			if i % g == 0:
				res = False
				break
	if res:
		print(g)
	else:
		print(0)


import math
for _ in range(int(input())):

	def solve():
		n = int(input())
		a = list(map(int, input().split()))
		odd = a[0]
		even = a[1]
		flag = 0
		for i in range(0, n, 2):
			odd = math.gcd(odd, a[i])
		for i in range(1, n, 2):
			even = math.gcd(even, a[i])
		for i in range(0, n, 2):
			if a[i] % even == 0:
				break
		else:
			return even
		for i in range(1, n, 2):
			if a[i] % odd == 0:
				break
		else:
			return odd
		return 0
	print(solve())


import sys
import math
t = int(sys.stdin.readline())
ans = []
for _ in range(t):
	n = int(sys.stdin.readline())
	nums = list(map(int, sys.stdin.readline().split()))
	(n1, n2) = (nums[0], nums[1])
	for i in range(2, len(nums), 2):
		n1 = math.gcd(n1, nums[i])
	for i in range(3, len(nums), 2):
		n2 = math.gcd(n2, nums[i])
	res = 0
	if n1 > 1:
		res = n1
		for x in nums[1::2]:
			if x % n1 == 0:
				res = 0
				break
	if res == 0 and n2 > 1:
		res = n2
		for x in nums[0::2]:
			if x % n2 == 0:
				res = 0
				break
	ans.append(str(res))
print('\n'.join(ans))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	(hcf1, hcf2) = (arr[0], arr[1])
	for i in range(n):
		if i & 1:
			hcf2 = math.gcd(hcf2, arr[i])
		else:
			hcf1 = math.gcd(hcf1, arr[i])
	flag = False
	for i in range(0, n, 2):
		if arr[i] % hcf2 == 0:
			flag = True
			break
	if not flag:
		print(hcf2)
		continue
	flag = False
	for i in range(1, n, 2):
		if arr[i] % hcf1 == 0:
			flag = True
			break
	if not flag:
		print(hcf1)
	else:
		print(0)


import math
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x1 = a[0]
	x2 = a[1]
	for i in range(0, n, 2):
		x1 = math.gcd(x1, a[i])
	for i in range(1, n, 2):
		x2 = math.gcd(x2, a[i])
	f = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % x1 != 0:
				f = 1
				break
		elif a[i] % x1 == 0:
			f = 1
			break
	if f == 0:
		print(x1)
		continue
	f = 0
	for i in range(n):
		if i % 2 == 0:
			if a[i] % x2 == 0:
				f = 1
				break
		elif a[i] % x2 != 0:
			f = 1
			break
	if f == 0:
		print(x2)
		continue
	print(0)


import math as m
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = l[1::2]
	b = l[::2]
	aa = a[0]
	bb = b[0]
	for i in range(1, len(a)):
		aa = m.gcd(a[i], aa)
	for i in range(1, len(b)):
		bb = m.gcd(b[i], bb)
	flag1 = 1
	flag2 = 1
	for x in a:
		if x % bb == 0:
			flag1 = 0
	for x in b:
		if x % aa == 0:
			flag2 = 0
	if flag1:
		print(bb)
		continue
	if flag2:
		print(aa)
		continue
	print(0)


from math import gcd
from functools import reduce
from types import new_class

def find_gcd(list):
	x = reduce(gcd, list)
	return x
for test in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(even_ele, odd_ele) = ([], [])
	for i in range(n):
		if i % 2 == 0:
			even_ele.append(arr[i])
		else:
			odd_ele.append(arr[i])
	gcd1 = find_gcd(even_ele)
	gcd2 = find_gcd(odd_ele)
	check_1 = 0
	check_2 = 0
	if gcd1 != 1:
		flag = 0
		for i in odd_ele:
			if i % gcd1 == 0:
				flag = 1
				break
		if flag == 0:
			pass
		else:
			check_1 = 1
	else:
		check_1 = 1
	if gcd2 != 1:
		flag = 0
		for i in even_ele:
			if i % gcd2 == 0:
				flag = 1
				break
		if flag == 0:
			pass
		else:
			check_2 = 1
	else:
		check_2 = 1
	if check_1 == 0:
		print(gcd1)
	elif check_2 == 0:
		print(gcd2)
	else:
		print(0)


from math import gcd
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ok = True
	g = 0
	for i in range(0, n, 2):
		g = gcd(g, A[i])
	for i in range(1, n, 2):
		if A[i] % g == 0:
			ok = False
			break
	if ok:
		print(g)
		continue
	ok = True
	g = 0
	for i in range(1, n, 2):
		g = gcd(g, A[i])
	for i in range(0, n, 2):
		if A[i] % g == 0:
			ok = False
			break
	print(g if ok else 0)


import math

def is_divisible(num, den):
	return num % den == 0
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	nums = list(map(int, input().split()))
	odd_gcd = nums[0]
	for j in range(2, len(nums), 2):
		odd_gcd = math.gcd(odd_gcd, nums[j])
	if odd_gcd > 1:
		all_not_divisble = True
		for j in range(1, len(nums), 2):
			if is_divisible(nums[j], odd_gcd):
				all_not_divisble = False
				break
		if all_not_divisble:
			print(odd_gcd)
			continue
	even_gcd = nums[1]
	for j in range(3, len(nums), 2):
		even_gcd = math.gcd(even_gcd, nums[j])
	if even_gcd > 1:
		all_not_divisble = True
		for j in range(0, len(nums), 2):
			if is_divisible(nums[j], even_gcd):
				all_not_divisble = False
				break
		if all_not_divisble:
			print(even_gcd)
			continue
	print(0)


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	odd = []
	even = []
	(og, eg) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			even.append(a[i])
			eg = math.gcd(a[i], eg)
		else:
			odd.append(a[i])
			og = math.gcd(a[i], og)
	new_o = list(map(lambda x: x % eg, odd))
	new_e = list(map(lambda x: x % og, even))
	if new_o.count(0) == 0:
		print(eg)
	elif new_e.count(0) == 0:
		print(og)
	else:
		print(0)


t = int(input())

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

def check(l, g):
	n = len(l)
	for i in range(n - 1):
		if l[i] % g == 0 and l[i + 1] % g == 0:
			return False
	return True
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	eg = l[0]
	for i in range(0, n, 2):
		eg = gcd(eg, l[i])
		if eg == 1:
			break
	og = l[1]
	for i in range(1, n, 2):
		og = gcd(og, l[i])
		if og == 1:
			break
	if eg == og:
		print(0)
		continue
	else:
		if eg != 1:
			eflag = True
		else:
			eflag = False
		if og != 1:
			oflag = True
		else:
			oflag = False
		if eflag:
			eflag = check(l, eg)
		if oflag:
			oflag = check(l, og)
		if not eflag and (not oflag):
			print(0)
			continue
		else:
			if eflag and (not oflag):
				print(eg)
				continue
			if oflag and (not eflag):
				print(og)
				continue
		if eflag and oflag:
			print(max(og, eg))
			continue
		print(0)


from math import gcd, trunc

def f(a, y, x):
	for i in range(len(a)):
		if i % 2 == y and a[i] % x == 0:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	s = [*map(int, input().split())]
	p = 0
	q = 0
	for i in range(n):
		if not i & 1:
			p = gcd(p, s[i])
		else:
			q = gcd(q, s[i])
	if p == q:
		print(0)
		continue
	if not f(s, 0, q) and (not f(s, 1, p)):
		print(0)
	elif f(s, 0, q) and q != 1:
		print(q)
	elif f(s, 1, p) and p != 1:
		print(p)


from collections import Counter
from math import ceil, floor, log
import bisect as bs
import sys
input = sys.stdin.readline
inp_lis = lambda : list(map(int, input().split()))
inp_multi = lambda : map(int, input().split())
inp_int = lambda : int(input().strip())
from fractions import gcd
from functools import reduce

def find_gcd(l):
	x = reduce(gcd, l)
	return x

def findNoIsDivisibleOrNot(n, l=[]):
	for i in range(0, len(l)):
		if l[i] % n == 0:
			return 1
	return 0
for _ in range(int(input().strip())):
	n = inp_int()
	a = inp_lis()
	x = []
	y = []
	for i in range(n):
		if i % 2 == 0:
			x.append(a[i])
		else:
			y.append(a[i])
	t1 = find_gcd(x)
	t2 = find_gcd(y)
	if (t1 > 1 or t2 > 1) and t1 != t2:
		if findNoIsDivisibleOrNot(t1, y) == 0:
			print(t1)
			continue
		elif findNoIsDivisibleOrNot(t2, x) == 0:
			print(t2)
			continue
		else:
			print(0)
	else:
		print(0)


from functools import reduce

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

def check(gc, arr):
	return reduce(lambda x, y: x * y, [i % gc for i in arr[::2]], arr[0]) != reduce(lambda x, y: x * y, [i % gc for i in arr[1::2]], arr[1])
for i in range(int(input())):
	input()
	arr = list(map(int, input().split()))
	gc1 = reduce(gcd, arr[::2], arr[0])
	gc2 = reduce(gcd, arr[1::2], arr[1])
	if check(gc1, arr):
		print(gc1)
	elif check(gc2, arr):
		print(gc2)
	else:
		print(0)


import math

def gcd(a, b):
	return math.gcd(a, b)
for i in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	(gcd1, gcd2, cnt) = (0, 0, 0)
	for j in range(n):
		if j % 2:
			gcd1 = gcd(gcd1, a[j])
		else:
			gcd2 = gcd(gcd2, a[j])
	if gcd1 != 1:
		for j in range(0, n, 2):
			if gcd(a[j], gcd1) == gcd1:
				break
		else:
			cnt += 1
			print(gcd1)
	if gcd2 != 1 and cnt == 0:
		for j in range(1, n, 2):
			if gcd(a[j], gcd2) == gcd2:
				break
		else:
			cnt += 1
			print(gcd2)
	if cnt == 0:
		print('0')


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for u in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	gc = -1
	for i in range(0, len(ar), 2):
		if gc == -1:
			gc = ar[i]
		else:
			gc = gcd(gc, ar[i])
	can = True
	for i in range(1, len(ar), 2):
		if ar[i] % gc == 0:
			can = False
			break
	if can:
		print(gc)
	else:
		can = True
		gc = -1
		for i in range(1, len(ar), 2):
			if gc == -1:
				gc = ar[i]
			else:
				gc = gcd(gc, ar[i])
		can = True
		for i in range(0, len(ar), 2):
			if ar[i] % gc == 0:
				can = False
				break
		if can:
			print(gc)
		else:
			print(0)


import math
import os
import sys
from sys import *
from decimal import *
from io import BytesIO, IOBase
import threading
from itertools import *
from collections import *
from array import *
import random
M = 10 ** 9 + 7
import heapq
import bisect
from functools import lru_cache
from queue import PriorityQueue
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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 fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchcount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] == key:
			return mid
		if arr[mid] <= key:
			left = mid + 1
		else:
			right = mid - 1
	return -1

def ternarysearch(arr, n, key):
	(l, r) = (0, n - 1)
	while l <= r:
		mid = (-l + r) // 3 + l
		mid2 = mid + (-l + r) // 3
		if arr[mid] == key:
			return mid
		if arr[mid2] == key:
			return mid2
		if arr[mid] > key:
			r = mid - 1
		elif arr[mid2] < key:
			l = mid2 + 1
		else:
			l = mid + 1
			r = mid2 - 1
	return -1

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def solven(p, l, a, b, n, res):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] <= A[i]:
				l[i] = max(l[i], l[k] + 1)
	return max(l)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)

def permute(a, l, r, p):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r, p)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def findCrossOver(arr, low, high, x):
	if arr[high] <= x:
		return high
	if arr[low] > x:
		return low
	mid = (low + high) // 2
	if arr[mid] <= x and arr[mid + 1] > x:
		return mid
	if arr[mid] < x:
		return findCrossOver(arr, mid + 1, high, x)
	return findCrossOver(arr, low, mid - 1, x)

def Kclosest(arr, x, k, n, ans):
	l = findCrossOver(arr, 0, n - 1, x)
	r = l + 1
	count = 0
	if arr[l] == x:
		l -= 1
	while l >= 0 and r < n and (count < k):
		if x - arr[l] < arr[r] - x:
			ans.append(arr[l])
			l -= 1
		else:
			ans.append(arr[r])
			r += 1
		count += 1
	while count < k and l >= 0:
		ans.append(arr[l])
		l -= 1
		count += 1
	while count < k and r < n:
		ans.append(arr[r])
		r += 1
		count += 1
	return ans

def dfs(root, nodeVal, nodeConnection, visited):
	leftVal = nodeVal[root][0]
	rightVal = nodeVal[root][1]
	solution = []
	if nodeConnection[root]:
		visited.add(root)
		for i in nodeConnection[root]:
			if i not in visited:
				solution.append(dfs(i, nodeVal, nodeConnection, visited))
		leftMax = 0
		rightMax = 0
		for i in solution:
			(l, r) = i
			leftMax += max(abs(leftVal - l[0]) + l[1], abs(leftVal - r[0]) + r[1])
			rightMax += max(abs(rightVal - l[0]) + l[1], abs(rightVal - r[0]) + r[1])
		return ((leftVal, leftMax), (rightVal, rightMax))
	else:
		return ((leftVal, 0), (rightVal, 0))

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

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

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def buildPrefix(MAX, prefix):
	prime = [1] * (MAX + 1)
	p = 2
	while p * p <= MAX:
		if prime[p] == 1:
			i = p * 2
			while i <= MAX:
				prime[i] = 0
				i += p
		p += 1
	for p in range(2, MAX + 1):
		prefix[p] = prefix[p - 1]
		if prime[p] == 1:
			prefix[p] += 1

def query(L, R, prefix):
	return prefix[R] - prefix[L - 1]

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def solvepp(n, k):
	if n == 1 and k == 1:
		return 0
	mid = 2 ** (n - 1) // 2
	if k <= mid:
		return solvepp(n - 1, k)
	else:
		return solvepp(n - 1, k - mid) == 0

def solvr(s, p):
	if len(s) == 0:
		print(p, end=' ')
		return
	op1 = p
	op2 = p + s[0]
	s = s[1:]
	solvr(s, op1)
	solvr(s, op2)
	return

def paranthesis(n, m, ans, l):
	if n == 0 and m == 0:
		print(ans)
		return
	if n != 0:
		op1 = ans + '('
		paranthesis(n - 1, m, op1, l)
	if m > n:
		op2 = ans + ')'
		paranthesis(n, m - 1, op2, l)

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

def lcs(s, r):
	rr = len(r)
	ss = len(s)
	l = [[0] * (rr + 1) for i in range(ss + 1)]
	for i in range(1, ss + 1):
		for j in range(1, rr + 1):
			if s[i - 1] == r[j - 1]:
				l[i][j] = l[i - 1][j - 1] + 1
			else:
				l[i][j] = max(l[i - 1][j], l[i][j - 1])
	return l[ss][rr]

def subsetsum(arr, sum, len):
	dp = [[False] * (sum + 1) for i in range(len + 1)]
	for i in range(len + 1):
		dp[i][0] = True
	for i in range(1, len + 1):
		for j in range(1, sum + 1):
			if arr[i - 1] > j:
				dp[i][j] = dp[i - 1][j]
			else:
				dp[i][j] = dp[i - 1][j] or dp[i - 1][j - arr[i - 1]]
	return dp[len][sum]

def matrixmincost(cost, n, m):
	dp = [[0 for x in range(m)] for x in range(n)]
	for i in range(n):
		for j in range(m):
			if i == 0 and j == 0:
				dp[i][j] = cost[i][j]
			elif i == 0 and j != 0:
				dp[i][j] = dp[i][j - 1] + cost[i][j]
			elif j == 0 and i != 0:
				dp[i][j] = dp[i - 1][j] + cost[i][j]
			else:
				dp[i][j] = cost[i][j] + min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1])
	return dp[n - 1][m - 1]

def coinchange(n, arr, len1):
	dp = [0] * (n + 1)
	dp[0] = 1
	for i in range(len1):
		for j in range(arr[i], n + 1):
			dp[j] += dp[j - arr[i]]
	return dp[n]

class Graph(object):

	def __init__(self, vertices):
		self.graph = defaultdict(list)
		self.V = vertices

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def connectedComponents(self):
		unvisited = set(range(self.V))
		queue = deque()
		count = 0
		while len(unvisited) > 0:
			count += 1
			v = next(iter(unvisited))
			unvisited.remove(v)
			queue.append(v)
			while len(queue) > 0:
				v = queue.popleft()
				for w in self.graph[v]:
					if w in unvisited:
						unvisited.remove(w)
						queue.append(w)
		return count

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def nge(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def nse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] > arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def catalan(n):
	if n == 0 or n == 1:
		return 1
	catalan = [0] * (n + 1)
	catalan[0] = 1
	catalan[1] = 1
	for i in range(2, n + 1):
		for j in range(i):
			catalan[i] += catalan[j] * catalan[i - j - 1]
	return catalan[n]

def find_shortest_path(graph, start, end, path):
	path = path + [start]
	if start == end:
		return path
	if start not in graph:
		return None
	shortest = None
	for node in graph[start]:
		if node not in path:
			newpath = find_shortest_path(graph, node, end, path)
			if newpath:
				if not shortest or len(newpath) < len(shortest):
					shortest = newpath
	return shortest

def test(n, d):
	a = random.randint(1, n - 2)
	p = pow(a, d, n)
	if p == 1 or p == n - 1:
		return True
	while d != n - 1:
		d *= 2
		p = pow(p, 2, n)
		if p == n - 1:
			return True
	return False

def isprime(n):
	if n == 1:
		return False
	if n == 2:
		return True
	if n == 3:
		return True
	d = n - 1
	while d % 2 == 0:
		d //= 2
	for i in range(5):
		if test(n, d) == False:
			return False
	return True

def muin(a, m):
	(x, y, mo) = (1, 0, m)
	if m == 1:
		return 0
	while m > 0:
		(x, y) = (y, x - a // m * y)
		(a, m) = (m, a % m)
	if x < 0:
		return mo + x
	else:
		return x

def good(l, c):
	ch = chr(c)
	if len(l) == 1:
		return 1 if ch != l[0] else 0
	k = len(l) // 2
	lm = k - l[:k].count(ch) + good(l[k:], c + 1)
	rm = k - l[k:].count(ch) + good(l[:k], c + 1)
	return min(lm, rm)

def facto(fact):
	(fact[0], fact[1]) = (1, 1)
	for i in range(2, 10 ** 5 + 1):
		fact[i] = fact[i - 1] * i % M

def comb(n, r, fact):
	return fact[n] * pow(fact[n - r] * fact[r], M - 2, M) % M

def numberToBase(n, b):
	if n == 0:
		return 0
	digits = []
	while n:
		digits.append(n % b)
		n //= b
	return sum(digits)

def main():
	tt = 1
	tt = inpu()
	for _ in range(tt):
		n = inpu()
		arr = lis()
		gcd1 = 0
		gcd2 = 0
		for i in range(n):
			if i % 2 == 0:
				gcd1 = math.gcd(gcd1, arr[i])
			else:
				gcd2 = math.gcd(gcd2, arr[i])
		if gcd1 == gcd2:
			print(0)
		else:
			flag = True
			for i in range(n):
				if i % 2 == 0:
					if arr[i] % gcd2 == 0:
						break
			else:
				flag = False
				print(gcd2)
				continue
			for i in range(n):
				if i % 2 != 0:
					if arr[i] % gcd1 == 0:
						break
			else:
				flag = False
				print(gcd1)
				continue
			print(0)
main()


t = int(input())
for i in range(t):
	import math
	n = int(input())
	a = list(map(int, input().split()))
	l1 = []
	l2 = []
	if n % 2 == 0:
		for i in range(n // 2):
			l1.append(a[2 * i])
			l2.append(a[2 * i + 1])
	else:
		for i in range(n // 2 + 1):
			l1.append(a[2 * i])
		for i in range((n - 1) // 2):
			l2.append(a[2 * i + 1])
	p = 0
	q = 0
	for i in l1:
		p = math.gcd(p, i)
	for i in l2:
		q = math.gcd(q, i)
	c1 = 0
	c2 = 0
	for i in l1:
		if i % q == 0:
			c1 = c1 + 1
	for i in l2:
		if i % p == 0:
			c2 = c2 + 1
	if c1 > 0 and c2 == 0:
		print(p)
	elif c1 == 0 and c2 > 0:
		print(q)
	elif c1 > 0 and c2 > 0:
		print(0)
	elif c1 == 0 and c2 == 0:
		print(q)


import math
sr = lambda : input()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
inf = 10 ** 18
mod = 998244353
test = ir()
for t in range(test):
	n = ir()
	a = lr()
	kouho1 = a[0]
	kouho2 = a[1]
	for i in range(1, n, 2):
		kouho1 = math.gcd(kouho1, a[i - 1])
		kouho2 = math.gcd(kouho2, a[i])
	if n % 2 == 1:
		kouho1 = math.gcd(kouho1, a[-1])
	flg1 = True
	flg2 = True
	for i in range(1, n, 2):
		if a[i - 1] % kouho2 == 0:
			flg1 = False
		if a[i] % kouho1 == 0:
			flg2 = False
	if n % 2 == 1:
		if a[-1] % kouho2 == 0:
			flg1 = False
	if not (flg1 or flg2):
		print(0)
	elif flg2:
		print(kouho1)
	else:
		print(kouho2)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
for _ in range(t):
	n = int(input())
	(*x,) = map(int, input().split())
	even = []
	odd = []
	for i in range(0, n):
		if i % 2 == 0:
			odd.append(x[i])
		else:
			even.append(x[i])
	first = odd[0]
	for i in range(1, len(odd)):
		first = gcd(first, odd[i])
	for i in even:
		if i % first == 0:
			first = 0
			break
	second = even[0]
	for i in range(1, len(even)):
		second = gcd(second, even[i])
	for i in odd:
		if i % second == 0:
			second = 0
			break
	print(max(first, second))


import sys
input = lambda : sys.stdin.readline().rstrip()
from math import gcd

def gcd_all(L):
	g = 0
	for a in L:
		g = gcd(g, a)
	return g

def calc(A, B):
	g = gcd_all(A)
	for b in B:
		if b % g == 0:
			break
	else:
		return g
	g = gcd_all(B)
	for a in A:
		if a % g == 0:
			break
	else:
		return g
	return 0
T = int(input())
for _ in range(T):
	N = int(input())
	I = [int(a) for a in input().split()]
	A = I[::2]
	B = I[1::2]
	print(calc(A, B))


def gcd(a):
	x = 0
	for y in a:
		while y:
			(x, y) = (y, x % y)
	return x

def problem(a):
	(even, odd) = (a[::2], a[1::2])
	(x, y) = (gcd(even), gcd(odd))
	if x and all((i % x != 0 for i in odd)):
		return x
	if y and all((i % y != 0 for i in even)):
		return y
	return 0
for _ in range(int(input())):
	input()
	print(problem(list(map(int, input().split()))))