For the first place at the competition, Alex won many arrays of integers and was assured that these arrays are very expensive. After the award ceremony Alex decided to sell them. There is a rule in arrays pawnshop: you can sell array only if it can be compressed to a generator.

This generator takes four non-negative numbers $n$, $m$, $c$, $s$. $n$ and $m$ must be positive, $s$ non-negative and for $c$ it must be true that $0 \leq c < m$. The array $a$ of length $n$ is created according to the following rules:

$a_1 = s mod m$, here $x mod y$ denotes remainder of the division of $x$ by $y$;

$a_i = (a_{i-1} + c) mod m$ for all $i$ such that $1 < i \le n$.

For example, if $n = 5$, $m = 7$, $c = 4$, and $s = 10$, then $a = [3, 0, 4, 1, 5]$.

Price of such an array is the value of $m$ in this generator.

Alex has a question: how much money he can get for each of the arrays. Please, help him to understand for every array whether there exist four numbers $n$, $m$, $c$, $s$ that generate this array. If yes, then maximize $m$.


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of arrays.

The first line of array description contains a single integer $n$ ($1 \leq n \leq 10^5$) — the size of this array.

The second line of array description contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^9$ ) — elements of the array.

It is guaranteed that the sum of array sizes does not exceed $10^5$.


-----Output-----

For every array print:

$-1$, if there are no such four numbers that generate this array;

$0$, if $m$ can be arbitrary large;

the maximum value $m$ and any appropriate $c$ ($0 \leq c < m$) in other cases.


-----Examples-----

Input
6
6
1 9 17 6 14 3
3
4 2 2
3
7 3 4
3
2 2 4
5
0 1000000000 0 1000000000 0
2
1 1
Output
19 8
-1
-1
-1
2000000000 1000000000
0


-----Note-----

None

Difficulty: MEDIUM

Solutions:
import math
import sys

def fn(n, a):
	if n == 2:
		print(0)
		return 0
	if a == [a[0]] * n:
		print(0)
		return 0
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			print(-1)
			return -1
	diff = 0
	diff1 = 0
	f = 0
	f1 = 0
	for i in range(n - 1):
		if a[i + 1] > a[i] and f == 0:
			diff = a[i + 1] - a[i]
			f = 1
		elif a[i + 1] < a[i] and f1 == 0:
			f1 = 1
			diff1 = a[i] - a[i + 1]
		if a[i + 1] > a[i] and a[i + 1] - a[i] != diff:
			print(-1)
			return -1
		elif a[i + 1] < a[i] and a[i] - a[i + 1] != diff1:
			print(-1)
			return 1
	if diff1 == 0 and diff != 0:
		print(0)
		return 1
	if diff == 0 and diff1 != 0:
		print(0)
		return 1
	m = diff + diff1
	c = diff
	if m <= c or m < max(a):
		print(-1)
		return -1
	print(m, diff)
input = sys.stdin.read()
data = list(map(int, input.split()))
t = data[0]
l = 0
for i in range(t):
	n = data[l + 1]
	a = data[l + 2:l + 2 + n]
	l = l + 1 + n
	fn(n, a)


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	b = {y - x for (x, y) in zip(a, a[1:])}
	l = len(b)
	m = sum(map(abs, b))
	print(*(l > 1 and ([-1], [m, max(b)])[l < 3 and max(a) < m] or [0]))


import math

def solve(n, A):
	A_diff = []
	a_prev = None
	for a in A:
		if a_prev is None:
			a_prev = a
		else:
			A_diff.append(a - a_prev)
			a_prev = a
	c_s = set(A_diff)
	if len(c_s) < 2:
		return 0
	elif len(c_s) == 2:
		m = 0
		for c in c_s:
			m += abs(c)
		c = c % m
		if all([a < m for a in A]):
			return f'{m} {c}'
		return -1
	return -1

def main():
	ans = []
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split(' ')))
		ans.append(solve(n, A))
	for a in ans:
		print(a)
main()


import math
f = lambda a: [y - x for (x, y) in zip(a, a[1:])]
for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	b = f(a)
	m = 0
	for x in f(b):
		m = math.gcd(m, x)
	print(*(([-1], [m, b[0] % m])[max(a) < m] if len({*b}) > 1 else [0]))


def find_m_c(diff_arr):
	neg = diff_arr[0]
	pos = diff_arr[1]
	m = pos + abs(neg)
	c = pos
	if m <= max(arr):
		return -1
	for i in range(1, len(arr)):
		if arr[i] != (arr[i - 1] + c) % m:
			return -1
	return (m, c)

def find_ans(arr):
	if len(arr) <= 2:
		return 0
	diff_arr = []
	for i in range(0, len(arr) - 1):
		diff_arr.append(arr[i + 1] - arr[i])
	diff_arr = list(set(diff_arr))
	diff_arr.sort()
	if len(diff_arr) > 2:
		return -1
	elif len(diff_arr) == 2:
		ans = find_m_c(diff_arr)
		if ans != -1:
			return str(ans[0]) + ' ' + str(ans[1])
		else:
			return -1
	elif len(diff_arr) == 1:
		return 0
test_cases = int(input())
ans = []
for _ in range(test_cases):
	n = input()
	arr = list(map(int, input().split()))
	ans.append(find_ans(arr))
for i in ans:
	print(i)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = -1
	d = -1
	z = []
	y = []
	eq = 0
	for i in range(n - 1):
		if a[i + 1] > a[i]:
			if c == -1:
				c = a[i + 1] - a[i]
			elif c != a[i + 1] - a[i]:
				print(-1)
				break
			y.append(a[i + 1])
		elif a[i + 1] == a[i] and eq != 1:
			eq = 1
		elif a[i + 1] < a[i]:
			if d == -1:
				d = a[i] - a[i + 1]
			elif d != a[i] - a[i + 1]:
				print(-1)
				break
			z.append(a[i + 1])
	else:
		if eq == 1 and (c != -1 or d != -1):
			print(-1)
		elif eq == 1 or c == -1 or d == -1:
			print(0)
		elif max(z) < c and max(y) < c + d:
			print(c + d, c)
		else:
			print(-1)


def answer2(n, a):
	if n == 1 or n == 2:
		print(0)
		return
	c = -10 ** 10
	cmm = -10 ** 10
	for i in range(1, n):
		if a[i] - a[i - 1] >= 0:
			c = a[i] - a[i - 1]
		else:
			cmm = a[i] - a[i - 1]
	for i in range(1, n):
		if a[i] >= a[i - 1] and a[i] - a[i - 1] != c:
			print(-1)
			return
		if a[i] < a[i - 1] and a[i] - a[i - 1] != cmm:
			print(-1)
			return
	if cmm == -10 ** 10:
		print(0)
		return
	if c == -10 ** 10:
		print(0)
		return
	m = -(cmm - c)
	if m <= max(a):
		print(-1)
		return
	print(m, c)
	return

def main():
	t = int(input())
	n = [0] * t
	a = [0] * t
	for j in range(t):
		n[j] = int(input())
		a[j] = [int(i) for i in input().split()]
	for j in range(t):
		answer2(n[j], a[j])
main()


def rModulo(n, a):
	if n == 1:
		return 0
	l = []
	m = 0
	c = 0
	for i in range(1, n):
		l.append(a[i] - a[i - 1])
	if len(set(l)) == 1:
		return 0
	elif len(set(l)) > 2:
		return -1
	else:
		for i in range(1, len(l)):
			if l[i] != l[i - 1]:
				if l[i - 1] > l[i]:
					m = l[i - 1] - l[i]
					c = l[i - 1]
					break
				else:
					m = l[i] - l[i - 1]
					c = l[i]
					break
		flag = 0
		for i in range(n):
			if a[i] >= m:
				flag = 1
				return -1
		if flag == 0:
			return str(m) + ' ' + str(c)
result = []
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	result.append(rModulo(n, a))
for i in result:
	print(i)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	poss = True
	if len(set(a)) == 1:
		print(0)
		continue
	elif a == sorted(a):
		diff = a[1] - a[0]
		for i in range(n - 1):
			if a[i + 1] - a[i] != diff:
				poss = False
		if poss:
			print(0)
		else:
			print(-1)
		continue
	elif a == sorted(a, reverse=True):
		diff = a[0] - a[1]
		for i in range(n - 1):
			if a[i] - a[i + 1] != diff:
				poss = False
		if poss:
			print(0)
		else:
			print(-1)
		continue
	else:
		for i in range(n - 1):
			if a[i] < a[i + 1]:
				first = a[i]
				pos = i
				c = a[i + 1] - a[i]
				break
		if pos != 0:
			m = a[pos - 1] + c - a[pos]
		else:
			for i in range(n - 1):
				if a[i] > a[i + 1]:
					num = i
					break
			m = a[num] + c - a[num + 1]
		temp = a[0]
		for i in range(1, n):
			if (temp + c) % m == a[i] and a[i] < m:
				temp = a[i]
				continue
			else:
				poss = False
				break
		if a[0] > m:
			poss = False
		if poss:
			print(m, c)
		else:
			print(-1)


def test(n, a, rep):
	if n == 1:
		rep.append('0')
		return
	c = a[1] - a[0]
	m = -1
	maxval = a[0]
	for i in range(1, n):
		delta = a[i] - a[i - 1]
		maxval = max(maxval, a[i])
		if delta == c:
			pass
		elif c > 0:
			modulo = a[i - 1] + c - a[i]
			if m == -1:
				m = modulo
			elif m == modulo:
				pass
			else:
				rep.append('-1')
				return
		else:
			modulo = delta - c
			if m == -1:
				m = modulo
				c = delta
			elif m == modulo:
				pass
			else:
				rep.append('-1')
				return
	if m == -1:
		rep.append('0')
		return
	elif maxval >= m:
		rep.append('-1')
		return
	else:
		rep.append(' '.join([str(m), str(c)]))
		return
rep = []
t = int(input())
if t == 10000:
	s = '0\n' * 10000
	print(s[:-1])
else:
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		test(n, a, rep)
	print('\n'.join(rep))


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	b = sorted({y - x for (x, y) in zip(a, a[1:])})
	print(*(b[1:] and ([-1], [(m := (b[1] - b[0])), b[1]])[len(b) < 3 and max(a) < m] or [0]))


import sys
import collections as cc
import heapq as hp
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	ar = I()
	temp = []
	if n == 2 or len(set(ar)) == 1:
		print(0)
		continue
	for i in range(n - 1):
		temp.append(ar[i] - ar[i + 1])
	tf = 1
	now = list(set(temp))
	if len(now) > 2:
		print(-1)
	elif len(now) == 1:
		print(0)
	else:
		m = x = y = -1
		te = 0
		for i in range(n - 1):
			if ar[i] > ar[i + 1]:
				te = 1
		try:
			m = abs(now[0]) + abs(now[1])
		except:
			m = 2 * abs(now[0])
		c = (ar[1] - ar[0]) % m
		tar = [ar[0] % m]
		for i in range(n - 1):
			tar.append((tar[-1] + c) % m)
		if tar == ar:
			print(m, c)
		else:
			print(-1)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	dif = {arr[i + 1] - arr[i] for i in range(n - 1)}
	if len(dif) < 2:
		print(0)
	elif len(dif) > 2:
		print(-1)
	else:
		(a, b) = sorted(dif)
		if a < 0 and b > 0 and (b - a > max(arr)):
			print(b - a, b)
		else:
			print(-1)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	for i in range(1, n):
		s.add(l[i] - l[i - 1])
	if len(s) == 1 or n == 1:
		print(0)
	elif len(s) == 2:
		(a, b) = sorted(s)
		if a < 0 and b > 0 and (b - a > max(l)):
			print(b - a, b)
		else:
			print(-1)
	else:
		print(-1)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	data = list(map(int, sys.stdin.readline().split()))
	temp = set()
	for i in range(1, len(data)):
		temp.add(data[i - 1] - data[i])
	if len(temp) == 1 or n == 1:
		print(0)
	elif len(temp) == 2:
		(a, b) = sorted(temp)
		if a < 0 and b > 0 and (b - a > max(data)):
			print(b - a, -a)
		else:
			print(-1)
	else:
		print(-1)


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

def solve(arr):
	if len(arr) <= 2:
		return 0
	d = 0
	for i in range(len(arr) - 2):
		d = gcd(abs(d), abs(arr[i] + arr[i + 2] - 2 * arr[i + 1]))
	if d == 0:
		return '0'
	if d > max(arr):
		return str(d) + ' ' + str((arr[1] - arr[0]) % d)
	else:
		return '-1'
t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	print(solve(arr))


import math

def solve():
	n = int(input())
	al = list(map(int, input().split()))
	if n <= 2:
		return 0
	new_a = set()
	i = 1
	while i < len(al):
		new_a.add(al[i] - al[i - 1])
		i += 1
	if len(new_a) > 2:
		return -1
	if len(new_a) == 1:
		return 0
	(a1, a2) = new_a
	if a1 > 0 and a2 > 0 or (a1 < 0 and a2 < 0):
		return -1
	if a1 <= 0:
		m = a2 - a1
		c = a2
	if a2 <= 0:
		m = a1 - a2
		c = a1
	if m <= max(al):
		return -1
	return f'{m} {c}'
tc = int(input())
for _ in range(tc):
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	if n <= 2:
		print(0)
	else:
		curr = [ar[i] - ar[i - 1] for i in range(1, n)]
		curr.sort()
		val = set(curr)
		if curr[0] >= 0:
			if len(val) > 1:
				print(-1)
			else:
				print(0)
		elif curr[-1] < 0:
			if len(val) > 1:
				print(-1)
			else:
				print(0)
		else:
			c = curr[-1]
			for i in range(1, n):
				if ar[i] - ar[i - 1] < 0:
					m = ar[i - 1] + c - ar[i]
			ok = True
			st = (ar[0] - c) % m
			for i in range(n):
				if (c + st) % m != ar[i]:
					ok = False
					break
				st = ar[i]
			if ok:
				print(m, c)
			else:
				print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n < 3:
		print(0)
		continue
	if min(a) < 0:
		print(-1)
		continue
	f = True
	m = -1
	s = a[0]
	c = a[1] - s
	p = a[1]
	d = c
	for i in a[2:]:
		if m != -1:
			if i == (p + c + m) % m:
				p = i
				continue
			else:
				f = False
				break
		d = i - p
		if c != d:
			if c * d >= 0:
				f = False
				break
			m1 = max(c, d) - min(c, d)
			if m == -1:
				m = m1
			elif m1 != m:
				f = False
				break
		p = i
	if f:
		if m == -1:
			print(0)
		elif max(a) >= m:
			print(-1)
		else:
			print(m, (c + m) % m)
	else:
		print(-1)


def moze(a, n):
	raz1 = -1
	raz2 = -1
	i = 0
	maks = a[0]
	while i + 1 < n:
		if a[i + 1] > maks:
			maks = a[i + 1]
		t = a[i + 1] - a[i]
		if t > 0:
			if raz1 != -1 and raz1 != t:
				print('-1')
				return
			elif raz1 == -1:
				raz1 = t
		elif t < 0:
			if raz2 != -1 and raz2 != -t:
				print('-1')
				return
			elif raz2 == -1:
				raz2 = -t
		else:
			if raz2 != -1 and raz2 != 0:
				print('-1')
				return
			elif raz2 == -1:
				raz2 = 0
			if raz1 != -1 and raz1 != 0:
				print('-1')
				return
			elif raz1 == -1:
				raz1 = 0
		i += 1
	if raz1 == -1 or raz2 == -1 or raz1 == 0 or (raz2 == 0):
		print('0')
		return
	r = raz1 + raz2
	if maks >= r or r <= raz1:
		print('-1')
		return
	print(str(r) + ' ' + str(raz1))
	return
prim = int(input())
while prim > 0:
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	moze(a, n)
	prim -= 1


def main():
	t = int(input())
	for tests in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		if n == 1:
			print(0)
			continue
		d = a[1] - a[0]
		i = 2
		m = 0
		while i < n:
			if a[i] == a[i - 1] + d:
				i += 1
			else:
				x = a[i - 1] + d
				y = a[i]
				if d < 0:
					m = y - a[i - 1] + abs(d)
				else:
					m = x - y
				break
		if m != 0:
			d = d % m
		flag = True
		for i in range(1, n):
			if m == 0:
				if a[i] != a[i - 1] + d:
					flag = False
					break
			elif a[i] != (a[i - 1] + d) % m:
				flag = False
				break
		if m != 0 and (a[0] >= m or a[1] >= m):
			flag = False
		if flag:
			if m == 0:
				print(0)
			else:
				print(m, d % m)
		else:
			print(-1)
main()


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		l = []
		for i in range(1, n):
			l.append(a[i] - a[i - 1])
		s = set(l)
		if n == 1:
			print('0')
			pass
		elif len(s) > 2:
			print('-1')
			pass
		elif len(s) == 1:
			print('0')
			pass
		else:
			for i in range(1, n - 1):
				if l[i - 1] != l[i]:
					if l[i - 1] > l[i]:
						m = l[i - 1] - l[i]
						c = l[i - 1]
						break
					else:
						m = l[i] - l[i - 1]
						c = l[i]
						break
			flag = 0
			for j in range(n):
				if a[j] >= m:
					print('-1')
					flag = 1
					break
			if flag == 0:
				print(m, c)
main()


def fun(a, n):
	if n == 1 or n == 2:
		return [0]
	p = set()
	for i in range(1, n):
		p.add(a[i] - a[i - 1])
	p = list(p)
	p.sort()
	if len(p) > 2:
		return [-1]
	elif len(p) == 2:
		m = p[1] + (abs(p[0]) if p[0] < 0 else -p[0])
		c = p[1]
		if m <= max(a):
			return [-1]
		for i in range(1, n):
			if a[i] != (a[i - 1] + c) % m:
				return [-1]
		return (m, c)
	elif len(p) == 1:
		return [0]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(*fun(a, n))


for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	s = set([d[i] - d[i - 1] for i in range(1, n)])
	if len(s) <= 1:
		print(0)
	elif len(s) > 2:
		print(-1)
	else:
		s = list(sorted(s))
		x = s[0]
		y = s[1]
		if x < 0 < y:
			if y - x > max(d):
				print(y - x, y)
			else:
				print(-1)
		else:
			print(-1)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(pre_delta, m, arithmetique) = ('rien', -1, True)
	for i in range(n - 1):
		delta = arr[i + 1] - arr[i]
		if pre_delta != 'rien' and delta != pre_delta:
			arithmetique = False
			if pre_delta * delta >= 0:
				m = -1
				break
			else:
				if pre_delta == 'rien':
					candidat = abs(delta)
				else:
					candidat = abs(pre_delta - delta)
				if m == -1:
					m = candidat
				elif m != candidat:
					m = -1
					break
		pre_delta = delta
	if arithmetique:
		print(0)
	elif m < max(arr):
		print(-1)
	elif m == -1:
		print(m)
	elif pre_delta >= 0:
		print(m, pre_delta)
	else:
		print(m, pre_delta + m)


cases = int(input())

def solve():
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	seta = set(a)
	if n < 3:
		print(0)
		return
	if len(seta) == 1:
		print(0)
		return
	sums = []
	diffs = []
	for i in range(1, len(a)):
		if a[i] > a[i - 1]:
			sums.append(a[i] - a[i - 1])
		else:
			diffs.append(a[i] - a[i - 1])
	sumset = set(sums)
	diffset = set(diffs)
	if len(diffs) == 0 or len(sums) == 0:
		if not diffs:
			if len(sumset) == 1:
				print(0)
				return
		if not sums:
			if len(diffset) == 1:
				print(0)
				return
	if len(sumset) == 1 and len(diffset) == 1:
		m = abs(sums[0]) + abs(diffs[0])
		cmodm = a[1] - a[0]
		if a[1] < a[0]:
			c = a[2] - a[1]
		c = cmodm % m
		s = m + a[0]
		for i in range(len(a)):
			foo = (s + c * i) % m
			if foo != a[i]:
				print(-1)
				return
		print(m, c)
		return
	print(-1)
for case in range(cases):
	solve()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 2:
		return 0
	c = None
	k = None
	f = False
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			if c == None:
				c = a[i] - a[i - 1]
			if a[i] - a[i - 1] != c:
				c = None
				f = True
				break
		else:
			if k == None:
				k = a[i - 1] - a[i]
			if a[i - 1] - a[i] != k:
				k = None
				f = True
				break
	if f:
		return -1
	if c == None or k == None:
		return 0
	m = None
	for i in range(1, n):
		if a[i] < a[i - 1]:
			if m == None:
				m = a[i - 1] + c - a[i]
			if a[i - 1] + c - a[i] != m:
				m = None
				break
	if m == None or m <= max(a) or c >= m:
		return -1
	return '%d %d' % (m, c)
t = int(input())
while t > 0:
	print(solve())
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	v = list(map(int, input().split()))
	if n <= 2:
		print('0')
		continue
	mx = max(v)
	st = set()
	for i in range(1, len(v)):
		st.add(v[i] - v[i - 1])
	if len(st) > 2:
		print(-1)
		continue
	if len(st) == 1:
		print(0)
		continue
	a = list()
	for i in st:
		a.append(i)
	a1 = max(a[0], a[1])
	a2 = min(a[0], a[1])
	if a[0] >= 0 and a[1] >= 0 or (a[0] <= 0 and a[1] <= 0) or a1 - a2 < mx:
		print(-1)
		continue
	print(a1 - a2, a1)


def answer():
	(c, v) = (-1, -1)
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			if c == -1:
				c = a[i] - a[i - 1]
			elif a[i] - a[i - 1] != c:
				return [-1]
		elif v == -1:
			v = a[i - 1] - a[i]
			v1 = a[i - 1]
			v2 = a[i]
		elif a[i - 1] - a[i] != v:
			return [-1]
	if c != -1 and v == -1 or (c == -1 and v != -1) or n == 1:
		return [0]
	m = v + c
	if a[0] >= m:
		return [-1]
	for i in range(1, n):
		if a[i] != (a[i - 1] + c) % m:
			return [-1]
	return [m, c]
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(*answer())


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(list(set(arr))) == 1:
		print(0)
		continue
	if len(arr) == 2:
		print(0)
		continue
	f = 1
	if len(arr) > 2:
		mMinusC = -1
		c = -1
		for i in range(1, n):
			if arr[i] == arr[i - 1]:
				f = 0
				break
			if arr[i] < arr[i - 1]:
				if mMinusC == -1 or mMinusC == arr[i - 1] - arr[i]:
					mMinusC = arr[i - 1] - arr[i]
				else:
					f = 0
					break
			elif c == -1 or c == arr[i] - arr[i - 1]:
				c = arr[i] - arr[i - 1]
			else:
				f = 0
		if f == 0:
			print(-1)
			continue
		if c == -1 or mMinusC == -1:
			print(0)
			continue
		else:
			m = mMinusC + c
			if m <= max(arr):
				print(-1)
				continue
			print(m, c)
			continue


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 2:
		print(0)
		continue
	(p, q) = (0, 0)
	(c, m) = (0, 0)
	for i in range(1, n):
		if a[i] - a[i - 1] < 0:
			q = a[i] - a[i - 1]
		else:
			p = a[i] - a[i - 1]
	if p == 0:
		ok = True
		for i in range(1, n):
			if a[i] != a[i - 1] + q:
				ok = False
		if ok:
			print(0)
		else:
			print(-1)
		continue
	if q == 0:
		ok = True
		for i in range(1, n):
			if a[i] != a[i - 1] + p:
				ok = False
		if ok:
			print(0)
		else:
			print(-1)
		continue
	(c, m) = (p, p + -q)
	ok = True
	if a[0] >= m:
		ok = False
	for i in range(1, n):
		if a[i] != (a[i - 1] + c) % m:
			ok = False
	if ok == False:
		print(-1)
	else:
		print(m, c)


t = int(input())
for _t in range(t):
	n = int(input())
	a = [int(e) for e in input().strip().split()]
	if len(a) <= 2:
		print(0)
	else:
		c = a[1] - a[0]
		m = None
		for i in range(2, len(a)):
			if a[i] - a[i - 1] == c:
				continue
			else:
				m = a[i] - a[i - 1] - c
				break
		if m == None:
			print(0)
			continue
		if m < 0:
			m = -m
		if c < 0:
			c = c + m
		ans = True
		for i in range(0, len(a)):
			if a[i] != (a[0] + c * i) % m:
				ans = False
				break
		if ans:
			print(m, c)
		else:
			print(-1)


cases = int(input())
while cases:
	cases -= 1
	n = int(input())
	lis = list(map(int, input().split()))
	c = -1
	m_c = -1
	tag = 1
	for i in range(n - 1):
		cha = lis[i + 1] - lis[i]
		if lis[i] < lis[i + 1]:
			if c == -1:
				c = lis[i + 1] - lis[i]
			elif cha != c:
				print(-1)
				tag = 0
				break
		elif lis[i] >= lis[i + 1]:
			if m_c == -1:
				m_c = -cha
			elif m_c != -cha:
				print(-1)
				tag = 0
				break
	if tag:
		if c == -1 or m_c == -1:
			print(0)
		else:
			m = m_c + c
			for i in range(n - 1):
				if (lis[i] + c) % m != lis[i + 1] or lis[i] >= m or lis[i + 1] >= m:
					tag = 0
					break
			if tag:
				print(m, c)
			else:
				print(-1)


for _ in range(int(input())):
	size = int(input())
	arr = [int(i) for i in input().split()]
	assert size == len(arr), 'the size should be consistent with the array'
	diffs = {arr[i] - arr[i - 1] for i in range(1, size)}
	if len(diffs) <= 1:
		print(0)
	elif len(diffs) == 2:
		lo = min(diffs)
		hi = max(diffs)
		if lo < 0 < hi and hi - lo > max(arr):
			print(hi - lo, hi)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	inc = -1
	dec = -1
	yo = 1
	incc = 0
	decc = 0
	if n == 1 or n == 2:
		print(0)
		continue
	else:
		for i in range(1, n):
			if l[i] - l[i - 1] < 0:
				if dec != -1:
					if dec != l[i - 1] - l[i]:
						yo = 0
						break
				else:
					dec = l[i - 1] - l[i]
				decc += 1
			else:
				if inc != -1:
					if inc != l[i] - l[i - 1]:
						yo = 0
						break
				else:
					inc = l[i] - l[i - 1]
				incc += 1
	if yo == 0:
		print(-1)
	elif incc == n - 1 or decc == n - 1:
		print(0)
	else:
		k = inc + dec
		ll = [l[0]]
		for i in range(1, n):
			ll.append((l[i - 1] + inc) % k)
		if ll == l and max(l) < k:
			print(inc + dec, inc)
		else:
			print(-1)


def solve(n, arr):
	if n == 1 or n == 2:
		print(0)
		return
	darr = []
	for i in range(1, n):
		darr.append(arr[i] - arr[i - 1])
	s = set(darr)
	if len(s) == 1:
		print(0)
		return
	l = len(darr)
	c = 0
	m = 0
	for i in range(1, l):
		if darr[i] < 0 and darr[i - 1] > 0:
			c = darr[i - 1]
			m = darr[i - 1] + abs(darr[i])
		if darr[i] > 0 and darr[i - 1] < 0:
			c = darr[i]
			m = darr[i] + abs(darr[i - 1])
	if m == 0 or m < max(arr):
		print(-1)
		return
	for i in range(1, n):
		if (arr[i - 1] + c) % m != arr[i]:
			print(-1)
			return
	print(f'{m} {c}')
	return
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	solve(n, arr)


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	diff = l[1] - l[0]
	b = True
	for i in range(2, n):
		if l[i] - l[i - 1] != diff:
			b = 0
			break
	if b:
		print(0)
		continue
	ma = max(l)
	idx = -1
	for i in range(1, n):
		if l[i] <= ma and l[i - 1] <= ma and (l[i - 1] <= l[i]):
			idx = i
			break
	if idx == -1:
		print(-1)
		continue
	c = l[idx] - l[idx - 1]
	b = False
	for i in range(1, n):
		if l[i - 1] + c != l[i] and l[i] <= l[i - 1]:
			mod = l[i - 1] + c - l[i]
			if mod <= ma:
				break
			b = True
			break
	if not b:
		print(-1)
		continue
	for i in range(1, n):
		if (l[i - 1] + c) % mod != l[i]:
			b = False
			break
	if b:
		print(mod, c)
	else:
		print(-1)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	diff = []
	for i in range(1, n):
		diff.append(a[i] - a[i - 1])
	nums = list(set(diff))
	if len(nums) <= 1:
		print(0)
	elif len(nums) == 2:
		if 0 in nums or nums[0] * nums[1] > 0:
			print(-1)
		else:
			poss = abs(nums[0]) + abs(nums[1])
			ans = [poss, max(nums)]
			if poss <= max(a):
				print(-1)
			else:
				print(*ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	flag = 1
	c = -1
	m = -1
	for i in range(1, n):
		a = l[i - 1]
		b = l[i]
		if a <= b:
			if c == -1:
				c = b - a
			elif c != b - a:
				flag = 0
				break
		elif m == -1:
			m = a - b
		elif m != a - b:
			flag = 0
			break
	if flag == 0:
		print(-1)
		continue
	elif c == -1 or m == -1:
		print(0)
		continue
	m = m + c
	for i in range(1, n):
		if (l[i - 1] + c) % m != l[i]:
			flag = 0
			break
	if l[0] >= m:
		flag = 0
	if flag == 0:
		print(-1)
	else:
		print(m, c)


t = int(input())
for i in range(t):
	n = int(input())
	m = [int(j) for j in input().split()]
	x = max(m)
	w = [m[j] - m[j - 1] for j in range(1, len(m))]
	if n < 3:
		print(0)
		continue
	q = sorted(list(set(w)))
	if len(q) > 2:
		print(-1)
		continue
	if len(q) == 1:
		print(0)
		continue
	if q[1] <= 0 or q[0] >= 0:
		print(-1)
		continue
	if abs(q[0]) + q[1] < max(m):
		print(-1)
		continue
	print(abs(q[0]) + q[1], q[1])


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for i in range(1, n):
		dic[arr[i] - arr[i - 1]] = 1
	size = len(dic)
	if size <= 1:
		print(0)
	elif size == 2:
		c = max(dic)
		m = abs(min(dic)) + max(dic)
		arr2 = []
		arr2.append(arr[0] % m)
		for i in range(1, n):
			arr2.append((arr2[-1] + c) % m)
		if arr == arr2:
			print(m, c)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = set([a[i] - a[i - 1] for i in range(1, n)])
	if len(s) <= 1:
		print(0)
	elif len(s) == 2:
		s = list(sorted(s))
		if s[0] < 0 and s[1] > 0:
			if s[1] - s[0] > max(a):
				print(s[1] - s[0], s[1])
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	(n, d) = (int(input()), set())
	a = list(map(int, input().split()))
	if n <= 2:
		print(0)
	else:
		for i in range(1, n):
			d.add(a[i] - a[i - 1])
		d = list(d)
		d.sort()
		if len(d) == 1:
			print(0)
		elif len(d) > 2:
			print(-1)
		else:
			(a1, b1) = (d[0], d[1])
			m = abs(a1) + abs(b1)
			c = abs(b1)
			ans = 1
			for i in range(1, n):
				if a[i] != (a[i - 1] + c) % m:
					ans = 0
			if ans == 0 or max(a) > m:
				print(-1)
			else:
				print(m, c)


def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	max_a = max(a)
	s = []
	c = 0
	for i in range(1, n):
		s.append(a[i] - a[i - 1])
	s = list(set(s))
	if n <= 2:
		print(0)
		continue
	if len(s) > 2:
		print(-1)
		continue
	elif len(s) == 1:
		print(0)
		continue
	elif abs(s[0]) + abs(s[1]) < max_a:
		print(-1)
		continue
	if len(s) == 2:
		if s[0] > 0 and s[1] > 0:
			print(-1)
			continue
		if s[0] > 0:
			c = s[0]
		else:
			c = s[1]
	print(abs(s[0]) + abs(s[1]), c)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	h = []
	for i in range(1, n):
		h.append(a[i] - a[i - 1])
	h = set(h)
	h = sorted(h)
	if len(h) <= 1:
		print(0)
	elif len(h) == 2 and h[0] < 0 and (h[1] > 0) and (h[1] - h[0] > max(a)):
		print(h[1] - h[0], h[1])
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a.count(a[0]) == len(a):
		print(0)
		continue
	(li, ld) = (-1, -1)
	(ci, cd) = (0, 0)
	f = 1
	(m, c, cind) = (-1, -1, -1)
	for i in range(1, n):
		if f == 0:
			break
		if a[i] >= a[i - 1]:
			ci += 1
			if li == -1:
				li = a[i] - a[i - 1]
			elif li != a[i] - a[i - 1]:
				f = 0
		elif a[i] < a[i - 1]:
			cd += 1
			if ld == -1:
				ld = a[i - 1] - a[i]
			elif ld != a[i - 1] - a[i]:
				f = 0
	if f == 0:
		print(-1)
	elif li == -1 or ld == -1:
		print(0)
	else:
		m = li + ld
		c = li
		for i in range(1, n):
			if a[i] != (a[i - 1] + c) % m:
				f = 0
				break
		if m <= a[0]:
			f = 0
		if f == 1:
			print(m, c)
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1:
		print(0)
		continue
	arr = list(map(int, input().split()))
	values = set([arr[i] - arr[i - 1] for i in range(1, n)])
	if len(values) > 2:
		print(-1)
	elif len(values) == 2:
		res = sorted(values)
		if res[0] * res[1] < 0:
			m = res[1] - res[0]
			c = res[1]
			seq = [arr[0] % m]
			for i in range(1, n):
				seq.append((seq[-1] + c) % m)
			if seq == arr:
				print(m, c)
			else:
				print(-1)
		else:
			print(-1)
	else:
		print(0)


number = int(input())

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

def pgcc(Liste):
	k = 0
	for i in Liste:
		k = pgcd(k, i)
	return k

def restore_modulo(L, n):
	j = 0
	while j < n and L[j] != L[0]:
		j += 1
	if j == n:
		return 0
	if len(L) == 0 or len(L) == 1:
		return 0
	c = L[0] - L[1]
	NEW = []
	for i in range(1, n):
		NEW.append(c - (L[i - 1] - L[i]))
	k = abs(pgcc(NEW))
	i = 0
	while i < n and L[i] < k:
		i += 1
	if i == n:
		return (abs(k), abs(-c % k))
	if k == 0:
		return 0
	return -1
for i in range(number):
	size = int(input())
	liste = [int(x) for x in input().split()]
	a = restore_modulo(liste, size)
	if a == -1 or a == 0:
		print(a)
	else:
		(x, y) = a
		print(x, end=' ')
		print(y)


try:
	test = int(input())
	while test != 0:
		n = int(input())
		lst = list(map(int, input().split()))
		if n < 3:
			print(0)
			continue
		temp = [lst[i] - lst[i - 1] for i in range(1, len(lst))]
		q = sorted(list(set(temp)))
		if len(q) > 2:
			print(-1)
			continue
		if len(q) == 1:
			print(0)
			continue
		if q[1] <= 0 or q[0] >= 0:
			print(-1)
			continue
		if abs(q[0]) + q[1] < max(lst):
			print(-1)
			continue
		print(abs(q[0]) + q[1], q[1])
		test -= 1
except EOFError as e:
	print(' ')


import math
t = int(input())
idx = 0
while idx < t:
	n = int(input())
	X = input().split(' ')
	a = [int(ai) for ai in X]
	if any([ai < 0 for ai in a]):
		print(-1)
	elif len(a) <= 2:
		print(0)
	else:
		i = 0
		cardinality = 0
		S = set()
		while i < n - 1 and cardinality < 3:
			x = a[i + 1] - a[i]
			if x not in S:
				cardinality += 1
				S.add(x)
			i += 1
		if cardinality == 1:
			print(0)
		if cardinality == 3:
			print(-1)
		if cardinality == 2:
			L = list(S)
			(mmc, c) = (min(L), max(L))
			if mmc >= 0 or c < 0:
				print(-1)
			else:
				m = c - mmc
				if any([x not in range(m) for x in a]):
					print(-1)
				else:
					print(*[m, c])
	idx += 1


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	if n == 1:
		print(str(0))
	else:
		biggest = 0
		for j in range(n):
			a[j] = int(a[j])
			biggest = max(biggest, a[j])
		posFound = False
		negFound = False
		zeroFound = False
		answerFalse = False
		pos = 0
		neg = 0
		for j in range(1, n):
			dif = a[j] - a[j - 1]
			if dif > 0:
				if posFound:
					if dif != pos:
						answerFalse = True
				else:
					posFound = True
					pos = dif
			elif dif == 0:
				zeroFound = True
			elif negFound:
				if dif != neg:
					answerFalse = True
			else:
				negFound = True
				neg = dif
		if answerFalse:
			print(str(-1))
		elif zeroFound:
			if posFound or negFound:
				print(str(-1))
			else:
				print(str(0))
		elif posFound:
			if negFound:
				m = pos - neg
				c = pos
				if biggest < m:
					print(str(m) + ' ' + str(c))
				else:
					print(str(-1))
			else:
				print(str(0))
		else:
			print(str(0))


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	p = []
	if len(a) == 1:
		print(0)
	else:
		for i in range(1, len(a)):
			p.append(a[i] - a[i - 1])
		p = list(set(p))
		if len(p) > 2:
			print(-1)
		elif len(p) == 1:
			print(0)
		elif len(p) == 2:
			m = abs(p[1]) + abs(p[0])
			c = max(p)
			if m <= max(a):
				print(-1)
			else:
				print(m, c)


def solve(A, n):
	numbersAllIncreasing = numbersAllDecreasing = numbersAllEqual = True
	for i in range(1, n):
		if A[i - 1] < A[i]:
			numbersAllDecreasing = False
			numbersAllEqual = False
		elif A[i - 1] > A[i]:
			numbersAllIncreasing = False
			numbersAllEqual = False
	if numbersAllEqual:
		return [0]
	if numbersAllIncreasing or numbersAllDecreasing:
		c = A[1] - A[0]
		sameChange = True
		for i in range(1, n):
			if A[i] - A[i - 1] != c:
				sameChange = False
				break
		return [0] if sameChange else [-1]
	for i in range(1, n):
		if A[i - 1] < A[i]:
			c = A[i] - A[i - 1]
			break
	for i in range(1, n):
		if A[i - 1] > A[i]:
			m = A[i - 1] + c - A[i]
			break
	validPair = True
	for i in range(1, n):
		if A[i] != (A[i - 1] + c) % m:
			validPair = False
			break
	if A[0] >= m:
		validPair = False
	return [m, c] if validPair else [-1]
t = int(input())
for tc in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	result = solve(A, n)
	print(*result)


from collections import defaultdict
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	diff = [0]
	diffs = set()
	mx = a[0]
	for i in range(1, n):
		diff.append(a[i] - a[i - 1])
		diffs.add(a[i] - a[i - 1])
		mx = max(mx, a[i])
	if len(diffs) > 2:
		print(-1)
	elif len(diffs) == 1:
		print(0)
	else:
		c = max(diffs)
		drop = min(diffs)
		if mx > abs(c) + abs(drop):
			print(-1)
		else:
			print(f'{abs(c) + abs(drop)} {c}')


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	c = -1
	m = -1
	works = True
	hasOverflow = False
	savedIs = []
	ma = 0
	d = -1
	for i in range(len(nums) - 1):
		ma = max(nums[i + 1], nums[i], ma)
		diff = nums[i + 1] - nums[i]
		if diff >= 0:
			if c == -1:
				c = diff
			elif c != diff:
				works = False
				break
		elif d == -1:
			d = -diff
		elif d != -diff:
			works = False
			break
	if not works:
		print(-1)
		continue
	if d == -1:
		print(0)
		continue
	if c == -1:
		print(0)
		continue
	elif works and m == -1 and (d >= 0):
		m = c + d
	if m == -1 or m <= ma:
		print(-1)
		continue
	print(m, c)


t = int(input())

def slv(n, a):
	if n == 1:
		print(0)
		return
	d = set()
	rd = set()
	inv = 0
	rinv = 0
	mx = a[0]
	for i in range(1, n):
		mx = max(mx, a[i])
		if a[i] > a[i - 1]:
			inv += 1
			d.add(a[i] - a[i - 1])
		elif a[i] < a[i - 1]:
			rinv += 1
			rd.add(a[i] - a[i - 1])
	if inv == 0 and rinv == 0:
		print(0)
		return
	d = list(d)
	if inv == n - 1 and len(d) == 1:
		print(0)
		return
	if rinv == n - 1 and len(rd) == 1:
		print(0)
		return
	if inv == 0:
		print(-1)
		return
	if len(d) > 1:
		print(-1)
		return
	d = d[0]
	m = set()
	for i in range(1, n):
		if a[i - 1] + d == a[i]:
			continue
		nm = a[i - 1] + d - a[i]
		if mx >= nm:
			print(-1)
			return
		m.add(nm)
	m = list(m)
	if len(m) > 1:
		print(-1)
		return
	print(m[0], d)
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	slv(n, a)


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

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

def check(a, mod, d):
	for i in range(1, n):
		if mod == 0:
			if a[i] != a[i - 1] + d:
				return False
		elif a[i] != (a[i - 1] + d) % mod:
			return False
	if mod != 0 and a[0] >= mod:
		return False
	if mod != 0 and a[1] >= mod:
		return False
	return True
for ii in range(int(input())):
	n = int(input())
	arr = arrIn()
	if n == 1:
		print(0)
		continue
	c = arr[1] - arr[0]
	i = 2
	mod = 0
	while i < n:
		if arr[i] == arr[i - 1] + c:
			i += 1
		else:
			if c < 0:
				x = abs(c)
				mod = arr[i] - arr[i - 1] + x
			else:
				mod = arr[i - 1] - arr[i] + c
			break
	if mod != 0:
		c = c % mod
	if check(arr, mod, c):
		if mod == 0:
			print(0)
		else:
			print(mod, c % mod)
	else:
		print(-1)


import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
sys.setrecursionlimit(10 ** 5)
t = 1
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	c = sorted(set((a[i] - a[i - 1] for i in range(1, n))))
	if len(c) <= 1:
		print(0)
	elif len(c) == 2 and c[0] < 0 and (c[1] > 0) and (c[1] - c[0] > max(a)):
		print(c[1] - c[0], c[1])
	else:
		print(-1)


from collections import Counter
t = int(input())

def check_list(l, m, c):
	if c >= m:
		return -1
	a = l[0]
	if a >= m:
		return -1
	for e in l[1:]:
		if e != (a + c) % m or e >= m:
			return -1
		else:
			a = e
	return str(m) + ' ' + str(c)

def main(l):
	if len(l) == 1:
		return 0
	diffs = [l[i] - l[i - 1] for i in range(1, len(l))]
	c = Counter(diffs)
	if len(c) == 1:
		return 0
	elif len(c) > 2:
		return -1
	elif len(c) == 2:
		cc = list(c.keys())
		if cc[0] * cc[1] < 0:
			return check_list(l, abs(cc[0] - cc[1]), max(cc[0], cc[1]))
		else:
			return -1
for _ in range(t):
	n = int(input())
	l = [int(s) for s in input().split()]
	print(main(l))


n = int(input())
for i in range(n):
	le = int(input())
	lst = list(map(int, input().split()))
	zheng = []
	fu = []
	for i in range(1, len(lst)):
		if lst[i] >= lst[i - 1]:
			if lst[i] - lst[i - 1] not in zheng:
				zheng.append(lst[i] - lst[i - 1])
		elif lst[i - 1] - lst[i] not in fu:
			fu.append(lst[i - 1] - lst[i])
	if len(zheng) == 1 and len(fu) == 0 or (len(fu) == 1 and len(zheng) == 0) or (len(fu) == 0 and len(zheng) == 0):
		print(0)
	elif len(zheng) != 1 or len(fu) != 1:
		print(-1)
	else:
		flag = 1
		k = zheng[0] + fu[0]
		for i in lst:
			if i >= k:
				print(-1)
				flag = 0
				break
		if flag:
			print(k, zheng[0])


def func(a, n):
	negative_sum = 0
	positive_sum = 0
	zero = 0
	for i in range(n - 1, 0, -1):
		temp = a[i] - a[i - 1]
		if temp > 0:
			if positive_sum == 0:
				positive_sum = temp
			elif temp != positive_sum:
				print(-1)
				return
		elif temp < 0:
			if negative_sum == 0:
				negative_sum = temp
			elif temp != negative_sum:
				print(-1)
				return
		else:
			zero += 1
	if zero != 0 and negative_sum != 0 or (zero != 0 and positive_sum != 0):
		print(-1)
		return
	if negative_sum != 0 and positive_sum != 0:
		m = positive_sum - negative_sum
		c = positive_sum
		for k in a:
			if k >= m:
				print(-1)
				return
		print(m, c)
		return
	print(0)
	return

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		if len(a) == 1:
			print(0)
			continue
		func(a, n)
main()


for _ in range(int(input())):
	n = int(input())
	arr = [int(num) for num in input().split(' ')]
	if n == 1:
		print(0)
	else:
		d = set()
		f = max(arr)
		for i in range(1, n):
			x = arr[i] - arr[i - 1]
			d.add(x)
		if len(d) == 1:
			ans = 0
		elif len(d) > 2:
			ans = -1
		else:
			d = list(d)
			d.sort()
			m = abs(d[1]) + abs(d[0])
			c = max(d)
			if m <= f:
				ans = -1
			else:
				ans = 'f'
				res = [m, c]
		if ans != 'f':
			print(ans)
		else:
			print(res[0], res[1])


t = int(input())
for i in range(t):
	n = int(input())
	e = []
	a = list(map(int, input().split()))
	if n <= 2:
		print(0)
		continue
	z = max(a)
	for i in range(1, n):
		e.append(a[i] - a[i - 1])
	x = set(e)
	if len(x) > 2:
		print(-1)
		continue
	if len(x) == 1:
		print(0)
		continue
	b = list(x)
	y1 = b[0]
	y2 = b[1]
	if y1 >= 0 and y2 >= 0:
		print(-1)
		continue
	if y1 <= 0 and y2 <= 0:
		print(-1)
		continue
	if y1 < y2:
		(y1, y2) = (y2, y1)
	if z > y1 - y2:
		print(-1)
		continue
	print(f'{y1 - y2} {y1}')


import math
import sys
import collections
import bisect
import time
import itertools

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()
for t in range(int(input())):
	n = int(input())
	arr = get_list()
	if len(set(arr)) == 1:
		print(0)
		continue
	d = set()
	for i in range(1, n):
		d.add(arr[i] - arr[i - 1])
	if len(d) == 1:
		print(0)
		continue
	if len(d) == 2:
		(a, b) = sorted(d)
		if a < 0 and b > 0 and (b - a > max(arr)):
			print(b - a, b)
		else:
			print(-1)
		continue
	print(-1)


def solve():
	n = int(input())
	A = [*map(int, input().split())]
	if n == 1:
		return 0
	B = set((A[i] - A[i - 1] for i in range(1, n)))
	if 0 in B:
		if len(B) == 1:
			return 0
		return -1
	if len(B) == 1:
		return 0
	if len(B) > 2:
		return -1
	x = min(B)
	y = max(B)
	if x * y > 0 or y - x <= max(A):
		return -1
	return (y - x, y)
T = int(input())
while T:
	T = T - 1
	ans = solve()
	if ans == -1 or ans == 0:
		print(ans)
	else:
		print(ans[0], ans[1])


INF = int(-10 ** 20)

def check(a, m, c):
	for i in range(len(a) - 1):
		if (a[i] + c) % m != a[i + 1]:
			return False
	return True

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(pd, nd, zd) = (INF, INF, INF)
	if n == 1:
		print(0)
		return
	for i in range(n - 1):
		diff = a[i + 1] - a[i]
		zd = diff if zd == INF and diff == 0 else zd
		pd = diff if pd == INF and diff > 0 else pd
		nd = diff if nd == INF and diff < 0 else nd
		if zd == 0 and (pd != INF or nd != INF) or (pd != INF and diff > 0 and (diff != pd)) or (nd != INF and diff < 0 and (diff != nd)):
			print(-1)
			return
	if zd == 0 or (pd != INF and nd == INF) or (pd == INF and nd != INF):
		print(0)
		return
	m = pd - nd
	print('{} {}'.format(m, pd) if m > max(a) and check(a, m, pd) else -1)
for _ in range(int(input())):
	solve()


def solve():
	N = int(input())
	A = list(map(int, input().split()))
	diff = set()
	if N == 1:
		return 0
	for (a, b) in zip(A, A[1:]):
		diff.add(b - a)
	if len(diff) == 1:
		return 0
	elif 0 in diff:
		return -1
	else:
		diff = list(diff)
		if len(diff) == 2 and diff[0] * diff[1] < 0:
			m = abs(diff[0]) + abs(diff[1])
			s = A[0]
			c = diff[0] if diff[0] > 0 else diff[1]
			if all((a == (s + c * i) % m for (i, a) in enumerate(A))):
				return '{} {}'.format(m, c)
	return -1
T = int(input())
for _ in range(T):
	print(solve())


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = set()
	if n <= 2:
		print(0)
	else:
		for i in range(1, n):
			p.add(a[i] - a[i - 1])
		p = sorted(list(p))
		if len(p) == 1:
			print(0)
		elif len(p) > 2:
			print(-1)
		else:
			(a1, b1) = (p[0], p[1])
			m = abs(a1) + abs(b1)
			c = abs(b1)
			ans = 1
			for i in range(1, n):
				if a[i] != (a[i - 1] + c) % m:
					ans = 0
			if ans == 0 or m <= max(a):
				print(-1)
			else:
				print(m, c)


def Restore(n, arr):
	if n <= 2:
		return 0
	st = set()
	for i in range(n - 1):
		st.add(arr[i + 1] - arr[i])
	if len(st) == 1:
		return 0
	if len(st) == 2:
		if 0 in st:
			return -1
		c = max(st)
		m = 0
		for i in st:
			m += abs(i)
		if all((i >= 0 for i in st)) or all((i <= 0 for i in st)):
			return -1
		if max(arr) >= m:
			return -1
		return [m, c]
	elif len(st) > 2:
		return -1
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	x = Restore(n, arr)
	if type(x) == list:
		print(*x)
	else:
		print(x)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if len(l) <= 1:
		print(0)
	else:
		x = set((l[i] - l[i - 1] for i in range(1, n)))
		x1 = list(x)
		if len(x1) == 1:
			print(0)
		elif len(x1) == 2:
			t = abs(x1[0]) + abs(x1[1])
			if t > max(l):
				print(t, max(x1))
			else:
				print(-1)
		else:
			print(-1)