------Read problems statements in Hindi,
Mandarin chinese
, Russian and Vietnamese as well. ------ 

During Eid, it's a tradition that each father gives his kids money which they can spend on entertainment.

Chef has $N$ coins; let's denote the value of coin $i$ by $v_{i}$. Since today is Eid, Chef is going to give one coin to each of his two children. He wants the absolute value of the difference between the values of coins given to the two children to be as small as possible, so that he would be as fair as possible. 

Help Chef by telling him the minimum possible difference between the values of the coins given to the two children. Of course, Chef cannot give the same coin to both children.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains $N$ space-separated integers $v_{1}, v_{2}, \dots, v_{N}$.

------  Output ------
For each test case, print a single line containing one integer — the minimum possible difference.

------  Constraints  ------
$1 ≤ T ≤ 100$
$2 ≤ N ≤ 10^{5}$
the sum of $N$ in all test cases does not exceed $5 \cdot 10^{5}$
$1 ≤ v_{i} ≤ 10^{6}$ for each valid $i$

------  Subtasks ------
Subtask #1 (30 points): the sum of $N$ in all test cases does not exceed $2,000$

Subtask #2 (70 points): original constraints

----- Sample Input 1 ------ 
2
3
1 4 2
3
1 3 3
----- Sample Output 1 ------ 
1
0
----- explanation 1 ------ 
Example case 1: Chef gives the coin with value $1$ to his first child and the coin with value $2$ to the second child, so the answer is $2-1 = 1$.

Example case 2: Chef gives each of his children a coin with value $3$, so the difference is $0$.

Source: codechef | Difficulty: EASY
Tags: Sorting

Greedy algorithms


Solutions:
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sorted(a)
	k = []
	for i in range(n - 1):
		x = s[i + 1] - s[i]
		k.append(x)
	print(min(100001, min(k)))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	h = []
	for i in range(n - 1):
		h.append(a[i + 1] - a[i])
	print(min(h))


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort()
	d = abs(arr[0] - arr[1])
	for i in range(0, len(arr) - 1):
		if abs(arr[i] - arr[i + 1]) <= d:
			d = abs(arr[i] - arr[i + 1])
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	d = abs(arr[0] - arr[1])
	for i in range(0, len(arr) - 1):
		if abs(arr[i] - arr[i + 1]) <= d:
			d = abs(arr[i] - arr[i + 1])
	print(d)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	d = l[1] - l[0]
	for i in range(1, n):
		diff = l[i] - l[i - 1]
		if diff < d:
			d = diff
	print(d)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	l = [l[i] - l[i - 1] for i in range(1, n)]
	print(min(l))


class Solution:

	def solve(self, array, length):
		array = sorted(array, reverse=True)
		ans = array[0] - array[1]
		prev = array[1]
		for value in array[2:]:
			diff = prev - value
			if diff < ans:
				ans = diff
			prev = value
		return ans

class Driver:

	def __init__(self):
		self._solver = Solution()

	def drive(self):
		test_cases = int(input().strip())
		for _ in range(test_cases):
			length = int(input().strip())
			array = list(map(int, input().strip().split(' ')))
			ans = self._solver.solve(array, length)
			print(ans)
Driver().drive()


T = int(input())
for i in range(T):
	n = int(input())
	v = list(map(int, input().split()))
	v.sort()
	d = v[1] - v[0]
	for i in range(1, n):
		diff = v[i] - v[i - 1]
		if diff < d:
			d = diff
	print(d)


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	l = list(map(int, input().split()))
	k = sorted(l)
	difference = []
	for j in range(n - 1):
		d = k[j + 1] - k[j]
		difference.append(d)
	print(min(difference))


T = int(input())
for t in range(T):
	N = int(input())
	V = list(map(int, input().split()))
	V.sort()
	MIN = 1000000
	for k in range(1, N):
		z = V[k] - V[k - 1]
		if z < MIN:
			MIN = z
	print(MIN)


n = int(input())
for i in range(n):
	l = int(input())
	lis = list(map(int, input().split()))
	lis.sort()
	min_d = float('inf')
	for i in range(0, l - 1):
		g = abs(lis[i] - lis[i + 1])
		if min_d > g:
			min_d = g
	print(min_d)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	d = l[1] - l[0]
	for j in range(1, n):
		dif = l[j] - l[j - 1]
		if dif < d:
			d = dif
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	coins = list(map(int, input().split()))
	coins.sort()
	diff = 10001
	for i in range(n - 1):
		if coins[i + 1] - coins[i] < diff:
			diff = coins[i + 1] - coins[i]
	print(diff)


t = int(input())
for i in range(t):
	N = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	d = arr[1] - arr[0]
	for i in range(1, N):
		dif = arr[i] - arr[i - 1]
		if dif < d:
			d = dif
	print(d)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	min_value = arr[1] - arr[0]
	for i in range(len(arr) - 1):
		if arr[i + 1] - arr[i] < min_value:
			min_value = arr[i + 1] - arr[i]
	print(min_value)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = 2000
	l.sort()
	l2 = []
	for i in range(n - 1, 0, -1):
		l2.append(l[i] - l[i - 1])
	print(min(l2))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	b = []
	for i in range(0, len(a) - 1):
		k = abs(a[i] - a[i + 1])
		b.append(k)
	print(min(b))


t = int(input())
for i in range(t):
	n = int(input())
	v = list(map(int, input().split()))
	l = []
	v.sort()
	for j in range(n - 1):
		diff = abs(v[j] - v[j + 1])
		l.append(diff)
	print(min(l))


t = int(input())
for i in range(t):
	x = int(input())
	lst = list(map(int, input().split()))
	lst.sort()
	n = 1000000
	for j in range(x - 1):
		m = lst[j + 1] - lst[j]
		if m <= n:
			n = m
	print(n)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ', n)))
	l.sort()
	c = l[0]
	for i in range(1, n):
		b = l[i] - l[i - 1]
		if b < c:
			c = b
	print(c)


x = int(input())
g = []
for nnh in range(0, x):
	gvx = int(input())
	s = str(input())
	l = s.split(' ')
	jjv = []
	for nnv in l:
		jjv.append(int(nnv))
	g.append(jjv)
for iiert in g:
	iiert.sort()
	umd = None
	for uup in range(0, len(iiert)):
		try:
			umdp = iiert[uup + 1] - iiert[uup]
			if umd == None:
				umd = umdp
			elif umdp < umd:
				umd = umdp
		except:
			break
	print(umd)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	diff = a[1] - a[0]
	for i in range(1, n):
		ans = a[i] - a[i - 1]
		if ans < diff:
			diff = ans
	print(diff)


t = int(input())
for _ in range(t):
	n = int(input())
	coins = list(map(int, input().split()))
	coins.sort()
	min_diff = abs(coins[0] - coins[1])
	for i in range(1, n - 1):
		diff = abs(coins[i] - coins[i + 1])
		if diff < min_diff:
			min_diff = diff
	print(min_diff)


for i in range(int(input())):
	y = int(input())
	l = list(map(int, input().split()))
	l.sort()
	k = []
	for j in range(y - 1):
		o = l[j] - l[j + 1]
		if o < 0:
			o = o * -1
		k.append(o)
	print(min(k))


for _ in range(int(input())):
	N = int(input())
	L = sorted(map(int, input().split()))
	min_diff = max(L)
	for i in range(N - 1):
		if abs(L[i] - L[i + 1]) < min_diff:
			min_diff = abs(L[i] - L[i + 1])
	print(min_diff)


t = int(input())
for i in range(t):
	N = int(input())
	V = list(map(int, input().split()))
	V.sort()
	m = V[1] - V[0]
	for i in range(len(V) - 1):
		if m > V[i + 1] - V[i]:
			m = V[i + 1] - V[i]
	print(m)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	val = abs(l[1] - l[0])
	for i in range(1, len(l) - 1):
		val = min(val, abs(l[i] - l[i + 1]))
	print(val)


for _ in range(int(input())):
	n = int(input())
	k = []
	v = list(map(int, input().split()))
	v = sorted(v)
	for i in range(n - 1):
		l = v[i + 1] - v[i]
		k.append(l)
	print(min(k))


n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	l.sort()
	diff = 1000000
	for j in range(len(l) - 1):
		if l[j + 1] - l[j] < diff:
			diff = l[j + 1] - l[j]
	print(diff)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	m = abs(l[0] - l[1])
	for i in range(n - 1):
		j = abs(l[i] - l[i + 1])
		if j < m:
			m = j
	print(m)


t = int(input())
res = []
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	mindif = 10000
	for k in range(n - 1):
		distance = abs(li[k] - li[k + 1])
		if distance == 0:
			mindif = 0
			break
		else:
			mindif = min(mindif, distance)
	res.append(str(mindif))
print('\n'.join(res))


for i in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	l = []
	A.sort()
	for j in range(N - 1):
		l.append(A[j + 1] - A[j])
	print(min(l))


for i in range(int(input())):
	n = int(input())
	v = list(map(int, input().split()))
	b = sorted(v)
	l = []
	for i in range(n - 1):
		x = b[i + 1] - b[i]
		l.append(x)
	print(min(l))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	a = sorted(a)
	for i in range(n - 1):
		dif = a[i + 1] - a[i]
		l.append(dif)
	print(min(100001, min(l)))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))[:n]
	l.sort()
	min_diff = l[0]
	for i in range(len(l) - 1):
		if abs(l[i] - l[i + 1]) < min_diff:
			min_diff = abs(l[i] - l[i + 1])
	print(min_diff)


for _ in range(int(input())):
	N = int(input())
	l = sorted(list(map(int, input().split())))
	mini = l[1] - l[0]
	for i in range(1, N):
		diff = l[i] - l[i - 1]
		if diff < mini:
			mini = diff
	print(mini)


t = int(input())
for _ in range(t):
	N = int(input())
	A = list(map(int, input().split()))
	A.sort()
	l = []
	z = 0
	for i in range(1, N):
		z = A[i] - A[i - 1]
		l.append(z)
	print(min(l))


t = int(input())
for i in range(t):
	n = int(input())
	n1 = list(map(int, input().split()))
	n1.sort()
	n2 = set(n1)
	l = []
	if len(n1) != len(n2):
		print(0)
	else:
		for j in range(len(n1) - 1):
			s = n1[j + 1] - n1[j]
			l.append(s)
		l.sort()
		print(l[0])


T = int(input())
for i in range(T):
	N = int(input())
	li = list(map(int, input().split()))
	li.sort()
	z = []
	amin = 0
	for j in range(N - 1):
		k = abs(li[j + 1] - li[j])
		z.append(k)
	amin = min(z)
	print(amin)


for _ in range(int(input())):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	l.sort()
	sum = l[1] - l[0]
	for x in range(1, n):
		if l[x] - l[x - 1] < sum:
			sum = l[x] - l[x - 1]
	print(sum)


for _ in range(int(input())):
	n = int(input())
	v = sorted(list(map(int, input().split())))
	ans = 1000000
	for i in range(n - 1):
		if ans > abs(v[i] - v[i + 1]):
			ans = abs(v[i] - v[i + 1])
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	l = sorted(l)
	mon = abs(l[0] - l[1])
	for j in range(2, n):
		mon = min(abs(l[j - 1] - l[j]), mon)
	print(mon)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	mind = 10 ** 6
	c = Counter(input().split())
	if c.most_common(1)[0][1] > 1:
		print(0)
		next
	else:
		coins = sorted([int(x) for x in c.elements()])
		for i in range(len(coins) - 1):
			diff = coins[i + 1] - coins[i]
			if diff == 1:
				print(1)
				break
			elif mind > diff:
				mind = diff
		else:
			print(mind)


import math
t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	mm = abs(arr[0] - arr[1])
	for i in range(2, n):
		mm = min(abs(arr[i - 1] - arr[i]), mm)
	print(mm)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	val = li[n - 1]
	for i in range(n - 1):
		if li[i + 1] - li[i] < val:
			val = li[i + 1] - li[i]
	print(val)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	f = []
	for k in range(len(l) - 1):
		f.append(abs(l[k] - l[k + 1]))
	print(min(f))


test_cases = int(input())
for i in range(test_cases):
	n = int(input())
	arr = list(map(int, input().split()))
	diff = []
	arr.sort()
	for i in range(n - 1):
		d = arr[i + 1] - arr[i]
		diff.append(d)
	print(min(diff))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	li = list()
	l.sort()
	for j in range(n - 1):
		y = l[j + 1] - l[j]
		li.append(y)
	print(min(li))


for _ in range(int(input())):
	n = int(input())
	coins = sorted(list(map(int, input().split())))
	d = coins[1] - coins[0]
	for i in range(1, n):
		diff = coins[i] - coins[i - 1]
		if diff < d:
			d = diff
	print(d)


for i in range(int(input())):
	num = int(input())
	lst = list(map(int, input().split()))
	s = set(lst)
	l = []
	if len(s) != num:
		print(0)
	else:
		lst2 = sorted(lst)
		for j in range(num - 1):
			diff = lst2[j + 1] - lst2[j]
			l.append(diff)
		print(min(l))


for _ in range(int(input())):
	n = int(input())
	a = input().split()
	aSorted = sorted(list(map(int, a)))
	dif = []
	for i in range(n):
		if i + 1 > n - 1:
			break
		dif.append(aSorted[i + 1] - aSorted[i])
	print(min(dif))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	m = []
	for i in range(n - 1):
		s = l[i + 1] - l[i]
		m.append(s)
	print(min(m))


n = int(input())
for i in range(n):
	sz = int(input())
	x = list(map(int, input().split(' ')))
	x.sort()
	j = 2
	mins = abs(x[0] - x[1])
	while j < len(x):
		d = abs(x[j - 1] - x[j])
		if mins > d:
			mins = d
		j += 1
	print(mins)