You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that 

- i ≠ j
- |ai + aj - K| is minimal possible

Output  the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case consists of two space separated integers - N and K respectively.

The second line contains N single space separated integers - a1, a2, ..., aN respectively.

-----Output-----
For each test case, output a single line containing two single space separated integers - the minimal possible value of |ai + aj - K| and the number of unordered pairs {i, j} for which this minimal difference is reached.

-----Constraints-----

- 1 ≤ T ≤ 50
- 1 ≤ ai, K ≤ 109
- N = 2 - 31 point.
- 2 ≤ N ≤ 1000 - 69 points.

-----Example-----
Input:
1   
4 9
4 4 2 6

Output:
1 4

-----Explanation:-----
The minimal possible absolute difference of 1 can be obtained by taking the pairs of a1 and a2, a1 and a4, a2 and a4, a3 and a4.

Difficulty: MEDIUM
Tags: Mathematics

Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	array = list(map(int, input().split()))
	count = 0
	mn = float('inf')
	for i in range(N):
		for j in range(i + 1, N):
			if abs(array[i] + array[j] - K) < mn:
				mn = abs(array[i] + array[j] - K)
				count = 1
			elif abs(array[i] + array[j] - K) == mn:
				count += 1
	print(mn, count)


t = int(input())
for i in range(t):
	l = []
	mi = 99999999999
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(n - 1):
		for k in range(j + 1, n):
			a1 = a[j]
			a2 = a[k]
			b1 = a1 + a2 - m
			b2 = abs(b1)
			l.append(b2)
			if mi > b2:
				mi = b2
	print(mi, l.count(mi))


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	result = [abs(a[x] + a[y] - k) for x in range(n) for y in range(x + 1, n)]
	minimum = min(result)
	print(minimum, result.count(minimum))


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


t = int(input())
for e in range(0, t):
	(n, k) = input().strip().split()
	n = int(n)
	k = int(k)
	a = list(map(int, input().strip().split()))
	low = float('inf')
	count = 0
	for i in range(0, n - 1):
		for j in range(i + 1, n):
			if abs(a[i] + a[j] - k) < low:
				low = abs(a[i] + a[j] - k)
				count = 1
			elif abs(a[i] + a[j] - k) == low:
				count += 1
	print(low, count)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	s = list(map(int, input().split()))
	c = 0
	t = float('inf')
	for j in range(N):
		for k in range(j + 1, N):
			if abs(s[j] + s[k] - K) < t:
				t = abs(s[j] + s[k] - K)
				c = 1
			elif abs(s[j] + s[k] - K) == t:
				c += 1
	print(t, c)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst1 = list()
	lst = [int(x) for x in input().split()]
	a = n - 1
	a = a * (a + 1) / 2
	for i in range(n):
		for j in range(i + 1, n):
			lst1.append(math.fabs(lst[i] + lst[j] - k))
	print(int(min(lst1)), lst1.count(min(lst1)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lst = sorted(list(map(int, input().split())), reverse=True)
	prev = 5000
	xv = []
	for i in range(n):
		for j in range(i, n):
			if i == j:
				continue
			v = abs(lst[i] + lst[j] - k)
			xv.append(v)
	mn = min(xv)
	print(mn, xv.count(mn))


from itertools import combinations
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l = list(combinations(l, 2))
	x = []
	for i in l:
		x.append(abs(sum(i) - k))
	print(min(x), x.count(min(x)))


from sys import stdin
T = int(stdin.readline().strip())
while T > 0:
	[N, K] = [int(n) for n in stdin.readline().strip().split()]
	arr = [int(n) for n in stdin.readline().strip().split()]
	minAbs = abs(arr[0] + arr[1] - K)
	count = 0
	for i in range(0, N - 1):
		for j in range(i + 1, N):
			absVal = abs(arr[i] + arr[j] - K)
			if absVal < minAbs:
				minAbs = absVal
				count = 1
			elif absVal == minAbs:
				count += 1
	print(minAbs, count)
	T -= 1


t = int(input())
while t >= 1:
	n = input()
	arr = n.split()
	a = int(arr[0])
	k = int(arr[1])
	c = input()
	c = c.split()
	arr1 = []
	sum = []
	for i in range(len(c)):
		arr1.append(int(c[i]))
	arr1.sort()
	numberofpairs = 0
	min_value = 10000000000
	count = 0
	assist = 0
	d = 0
	f = 0
	while d < len(arr1):
		e = d + 1
		while e < len(arr1):
			if abs(arr1[d] + arr1[e] - k) < min_value:
				min_value = abs(arr1[d] + arr1[e] - k)
				count = 1
			elif abs(arr1[d] + arr1[e] - k) == min_value:
				count = count + 1
			e = e + 1
		d = d + 1
	print('{} {}'.format(min_value, count))
	t = t - 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list1.sort()
	min1 = 1000000000000001
	maxsum = 0
	for i in range(len(list1)):
		for j in range(i + 1, len(list1)):
			temp = abs(list1[i] + list1[j] - k)
			if temp < min1:
				min1 = min(min1, temp)
	if min1 != 0:
		cand1 = k + min1
		cand2 = k - min1
		s = list()
		cnt = 0
		for i in list1:
			t1 = cand1 - i
			if t1 in s:
				cnt += s.count(t1)
			t2 = cand2 - i
			if t2 in s:
				cnt += s.count(t2)
			s.append(i)
		print(min1, cnt)
	else:
		cand = k + min1
		s = list()
		cnt = 0
		for i in list1:
			t1 = cand - i
			if t1 in s:
				cnt += s.count(t1)
			s.append(i)
		print(min1, cnt)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	mn = abs(l[0] + l[1] - k)
	for i in range(n - 1):
		for j in range(i + 1, n):
			temp = abs(l[i] + l[j] - k)
			if temp == mn:
				c += 1
			elif temp < mn:
				mn = temp
				c = 1
			elif l[i] + l[j] - k > mn:
				break
	print(mn, c)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ind = 1
	m = 10 ** 10
	for i in range(n):
		for j in range(i + 1, n):
			if abs(m) > abs(a[i] + a[j] - k):
				m = abs(a[i] + a[j] - k)
				ind = 1
			elif abs(m) == abs(a[i] + a[j] - k):
				ind += 1
	print(m, ind)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l1 = list()
	for i in range(n):
		for j in range(i, n):
			if i != j:
				l1.append(abs(l[i] + l[j] - k))
	print(min(l1), l1.count(min(l1)))


from collections import *
for u in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	d = []
	x = 100000000000000
	for i in range(n - 1):
		for j in range(i + 1, n):
			x = min(x, abs(l[i] + l[j] - k))
			d.append(abs(l[i] + l[j] - k))
	print(x, d.count(x))


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	list_diff = []
	for i in range(n):
		for j in range(i + 1, n):
			list_diff.append(abs(arr[i] + arr[j] - k))
	m = min(list_diff)
	ans = list_diff.count(m)
	print(m, end=' ')
	print(ans)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = []
	for i in range(n):
		for j in range(i + 1, n):
			d.append(abs(l[i] + l[j] - k))
	print(min(d), d.count(min(d)))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = 3 * 10 ** 9
	a = []
	for i in range(n):
		for j in range(i + 1, n):
			a.append(abs(l[j] + l[i] - k))
	m = min(a)
	print(m, a.count(m))
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	x = []
	for i in range(n):
		for j in range(i + 1, n):
			x.append(abs(arr[i] + arr[j] - k))
	print(min(x), x.count(min(x)))


def inp():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n >= 2 and n <= 1000:
		l = list(map(int, input().split()))
		l = l[:n]
		le = len(l)
		s = []
		p = []
		i = 0
		while i < le:
			j = le - 1
			while j > i:
				s.append(l[i] + l[j])
				j = j - 1
			i = i + 1
		for i in s:
			d = k - i
			if d < 0:
				p.append(-d)
			else:
				p.append(d)
		m = min(p)
		c = p.count(m)
		print(m, c)
t = int(input())
if t > 0 and t <= 50:
	for i in range(0, t):
		inp()


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	l = []
	for k in range(N):
		for j in range(k + 1, N):
			if k != j:
				l.append(abs(L[k] + L[j] - K))
	print(min(l), l.count(min(l)))


import sys
import collections

def lower_bound(A, first, last, value):
	step = 0
	count = last - first
	index = 0
	while count > 0:
		index = first
		step = count // 2
		index += step
		if A[index] < value:
			index += 1
			first = index
			count -= step + 1
		else:
			count = step
	return first
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	numbers_count = collections.Counter()
	for a in A:
		numbers_count[a] += 1
	min_result = sys.maxsize
	num_min_result = 0
	for i in range(0, N - 1):
		result = sys.maxsize
		num_result = 0
		numbers_count[A[i]] -= 1
		if A[i] >= K:
			result = abs(A[i] + A[i + 1] - K)
			num_result = numbers_count[A[i + 1]]
		else:
			it = lower_bound(A, i + 1, len(A), K - A[i])
			if it == len(A):
				result = abs(A[i] + A[-1] - K)
				num_result = numbers_count[A[-1]]
			elif A[it] == K - A[i]:
				result = 0
				num_result = numbers_count[A[it]]
			else:
				result_prev = abs(A[i] + A[it - 1] - K) if it - 1 > i else sys.maxsize
				result_it = abs(A[i] + A[it] - K)
				if result_prev < result_it:
					result = result_prev
					num_result = numbers_count[A[it - 1]]
				elif result_prev > result_it:
					result = result_it
					num_result = numbers_count[A[it]]
				else:
					result = result_it
					num_result = numbers_count[A[it - 1]] + numbers_count[A[it]]
		if result == min_result:
			num_min_result += num_result
		elif result < min_result:
			min_result = result
			num_min_result = num_result
	print(str(min_result) + ' ' + str(num_min_result))


for _ in range(int(input())):
	(a, k) = map(int, input().split())
	result = []
	lst = list(map(int, input().split()))
	for i in range(len(lst) - 1):
		for j in range(i + 1, len(lst)):
			a = abs(lst[i] + lst[j] - k)
			result.append(a)
	print(min(result), result.count(min(result)))


t = int(input())
while t:
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	num = [[0 for i in range(n)] for j in range(n)]
	i = 0
	j = 0
	count = 0
	while i < n:
		while j < n:
			num[i][j] = arr[i] + arr[j]
			j = j + 1
		i = i + 1
		j = 0
	min = 1000000000000000
	i = 0
	j = 0
	while i < n:
		while j < n:
			if abs(num[i][j] - k) == min and i != j:
				count = count + 1
			elif abs(num[i][j] - k) <= min and i != j:
				min = abs(num[i][j] - k)
				count = 1
			j = j + 1
		i = i + 1
		j = i
	print('{} {}'.format(min, count))
	t = t - 1


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	t -= 1
	l = list(map(int, input().split()))
	sum = 0
	a = []
	for i in range(0, n):
		for j in range(i + 1, n):
			x = l[i] + l[j] - k
			x = abs(x)
			a.append(x)
	q = min(a)
	z = a.count(q)
	print(q, z)


t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	l = input().split()
	for i in range(n):
		l[i] = int(l[i])
	i = 0
	m = []
	while i < n - 1:
		s = i + 1
		while s < n:
			(x, y) = (l[i], l[s])
			tot = x + y - k
			if tot < 0:
				tot = -tot
			m.append(tot)
			s = s + 1
		i = i + 1
	print(str(min(m)) + ' ' + str(m.count(min(m))))


t = int(input())
for i in range(t):
	B = list(map(eval, input().split()))
	A = list(map(eval, input().split()))
	count = 0
	minimum = 10000000000
	for j in range(len(A) - 1):
		for m in range(j + 1, len(A)):
			if abs(A[j] + A[m] - B[1]) < minimum:
				count = 0
				minimum = abs(A[j] + A[m] - B[1])
			if abs(A[j] + A[m] - B[1]) == minimum:
				count += 1
	L = []
	L.append(minimum)
	L.append(count)
	print(*L)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	m = abs(A[0] + A[1] - K)
	c = 0
	for i in range(N - 1):
		for j in range(i + 1, N):
			m = min(abs(A[i] + A[j] - K), m)
	for i in range(N - 1):
		for j in range(i + 1, N):
			if abs(A[i] + A[j] - K) == m:
				c += 1
	print(m, c)


from random import randint

class Solution(object):

	def __init__(self):
		self.min_num = 0
		self.min_val = 0
		self.t = int(input())
		self.n = self.k = 0
		self.data = []
		for _ in range(self.t):
			self.get_data()
			self.solve()
			self.print_answer()
			self.clear_data()
	pass

	def get_data(self):
		(self.n, self.k) = map(int, input().split())
		self.data = list(map(int, input().split()))
		pass

	def print_answer(self):
		print('%d %d' % (self.min_val, self.min_num))
		pass

	def clear_data(self):
		self.data.clear()
		self.min_num = self.min_val = self.n = self.k = 0
		pass

	def solve(self):
		self.min_val = 2 * pow(10, 9) + 1
		self.data.sort()
		for i in range(self.n - 1):
			for j in range(i + 1, self.n):
				x = abs(self.data[i] + self.data[j] - self.k)
				if x < self.min_val:
					self.min_val = x
					self.min_num = 1
				elif x == self.min_val:
					self.min_num += 1
		pass

	@classmethod
	def create_test(cls):
		t_lim = 1
		t = randint(1, pow(10, t_lim))
		print(t)
		for _ in range(t):
			n_lim = 1
			k_lim = 1
			a_lim = 1
			n = randint(1, pow(10, n_lim))
			k = randint(1, pow(10, k_lim))
			print('%d %d' % (n, k))
			for _ in range(n):
				a = randint(1, pow(10, a_lim))
				print(a, end=' ')
			print()
		exit(0)
		pass

def main():
	Solution()
	pass
main()


tests = int(input())
for i in range(tests):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	checked_numbers = set()
	gap = abs(k - (arr[0] + arr[1]))
	freq = {}
	for j in range(n):
		if arr[j] in freq:
			freq[arr[j]] += 1
		else:
			freq[arr[j]] = 1
		if arr[j] not in checked_numbers:
			for l in range(j + 1, n):
				gap = min(gap, abs(k - (arr[j] + arr[l])))
			checked_numbers.add(arr[j])
	ans = 0
	used_combinations = set()
	for j in freq.keys():
		possiblities = [k + gap, k - gap]
		for required in possiblities:
			if required - j in freq and (j, required - j) not in used_combinations and ((required - j, j) not in used_combinations):
				if required - j == j:
					ans += freq[j] * (freq[j] - 1) // 2
				else:
					ans += freq[j] * freq[required - j]
					used_combinations.add((j, required - j))
	print(gap, ans)


T = int(input())
for i in range(T):
	(n, k) = [int(s) for s in input().split()]
	l = [int(s) for s in input().split()]
	m = []
	for j in range(n):
		for a in range(j + 1, n):
			m.append(abs(l[a] + l[j] - k))
	print(min(m), m.count(min(m)))


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


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mini = 10000000000000000000
	l = [int(i) for i in input().split()]
	cmaxi = 0
	for i in range(n):
		for j in range(i + 1, n):
			curr = abs(l[i] + l[j] - k)
			if curr < mini:
				mini = curr
				cmaxi = 1
			elif curr == mini:
				cmaxi += 1
	print(mini, cmaxi)


for t in range(int(input())):
	temp = list(map(int, input().split()))
	n = temp[0]
	k = temp[1]
	a = list(map(int, input().split()))
	count = 0
	minn = -1
	for i in range(n):
		for j in range(i + 1, n):
			if minn == -1:
				count += 1
				minn = abs(a[i] + a[j] - k)
			elif abs(a[i] + a[j] - k) == minn:
				count += 1
			elif abs(a[i] + a[j] - k) < minn:
				minn = abs(a[i] + a[j] - k)
				count = 1
	print(minn, count)


def solution():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	min_val = 10000000000.0
	count = 0
	for i in range(N):
		for j in range(i + 1, N):
			dif = abs(A[i] + A[j] - K)
			if min_val > dif:
				min_val = dif
				count = 1
			elif min_val == dif:
				count += 1
	print(min_val, end=' ')
	print(count)
T = int(input())
while T > 0:
	T = T - 1
	solution()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	aux = []
	for i in range(len(l)):
		for j in range(i + 1, len(l)):
			aux.append(abs(l[i] + l[j] - k))
	m = min(aux)
	t_1 = aux.count(m)
	print(m, t_1)


t = int(input())
for T in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	val = abs(a[0] + a[1] - k)
	c = 0
	for i in range(n):
		for j in range(i + 1, n):
			if val == abs(a[i] + a[j] - k):
				c += 1
			elif val > abs(a[i] + a[j] - k):
				val = abs(a[i] + a[j] - k)
				c = 1
			else:
				continue
	print(val, c)


t = int(input())
while t:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	import array
	arr = [int(x) for x in input().split()]
	mn = 1e+18
	cnt = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if abs(arr[i] + arr[j] - k) < mn:
				mn = abs(arr[i] + arr[j] - k)
	for i in range(n - 1):
		for j in range(i + 1, n):
			if abs(arr[i] + arr[j] - k) == mn:
				cnt += 1
	print(mn, cnt)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	m = 100
	d = []
	for i in range(n - 1):
		for j in range(i + 1, n):
			m = abs(l[i] + l[j] - k)
			d.append(m)
	m = min(d)
	c = d.count(m)
	print(m, '', c)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = []
	for i in range(n):
		for j in range(i + 1, n):
			z = abs(a[i] + a[j] - k)
			c.append(z)
	r = min(c)
	s = c.count(r)
	print(r, s)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = [int(x) for x in input().split()]
	min = 1000000000000
	c = 0
	for i in range(len(l) - 1):
		for j in range(i + 1, len(l)):
			if min > abs(l[i] + l[j] - b):
				min = abs(l[i] + l[j] - b)
				c = 1
			elif abs(l[i] + l[j] - b) == min:
				c = c + 1
	print(min, c)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	count = 0
	minVal = float('infinity')
	for i in range(n):
		for j in range(i + 1, n):
			diff = abs(arr[i] + arr[j] - k)
			if minVal > diff:
				count = 1
				minVal = diff
			elif diff == minVal:
				count += 1
	print(minVal, count)


n1 = int(input())
for i in range(n1):
	(n, b) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	s = []
	for j in range(0, n - 1):
		for k in range(j + 1, n):
			s.append(abs(l[j] + l[k] - b))
	p = min(s)
	c = 0
	for j in s:
		if j == p:
			c = c + 1
	print(p, c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	min = 2 ** 31 - 1
	for i in range(n):
		for j in range(i + 1, n):
			diff = abs(l[i] + l[j] - k)
			if min > diff:
				min = abs(l[i] + l[j] - k)
			if diff in d:
				d[diff] = d[diff] + 1
			else:
				d[diff] = 1
	print(min, d[min])


t = int(input())
for m in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = abs(a[0] + a[1] - k)
	c = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			x = abs(a[i] + a[j] - k)
			if x < ans:
				ans = x
				c = 1
			elif x == ans:
				c += 1
	print(ans, c)


from sys import stdin, stdout

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

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
t = int(sin())
for _ in range(t):
	(n, k) = listInput()
	(mc, mv) = (0, 2 * 10 ** 9)
	li = listInput()
	for i in range(n):
		for j in range(i + 1, n):
			te = int(abs(li[i] + li[j] - k))
			if te < mv:
				(mv, mc) = (te, 1)
			elif te == mv:
				mc += 1
	print(mv, mc)


from itertools import combinations
for t in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	li2 = list(combinations(li, 2))
	(mn, ct) = (10000000000, 0)
	for x in li2:
		if abs(x[0] + x[1] - k) < mn:
			mn = abs(x[0] + x[1] - k)
	for x in li2:
		if abs(x[0] + x[1] - k) == mn:
			ct += 1
	print(mn, ct)


import sys
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	minimum = sys.maxsize
	count = 0
	for j in range(n):
		for m in range(j + 1, n):
			x = abs(l[j] + l[m] - k)
			if x < minimum:
				count = 1
				minimum = x
			elif x == minimum:
				count += 1
	print(minimum, count)


t = int(input())
for I in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = []
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			b.append(abs(a[i] + a[j] - k))
	count = 0
	p = min(b)
	for i in b:
		if i == p:
			count += 1
	print(p, count)


from array import array
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	vals = array('i', map(int, input().split()))
	hmap = dict()
	for i in range(n - 1):
		for j in range(i + 1, n):
			add = abs(vals[i] + vals[j] - k)
			hmap[add] = hmap.get(add, 0) + 1
	min_val = min(list(hmap.keys()))
	freq = hmap[min_val]
	print(min_val, ' ', freq)


tests = int(input())
for i in range(tests):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	gap = 10 ** 11
	count = 0
	for j in range(n):
		for l in range(j + 1, n):
			temp = abs(arr[j] + arr[l] - k)
			if temp < gap:
				gap = temp
				count = 1
			elif temp == gap:
				count += 1
	print(gap, count)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = 3 * 10 ** 9
	c = 0
	for i in range(n):
		for j in range(i + 1, n):
			y = abs(l[j] + l[i] - k)
			if y < x:
				x = y
	for i in range(n):
		for j in range(i + 1, n):
			if abs(l[j] + l[i] - k) == x:
				c += 1
	print(x, c)
	t -= 1


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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	minimum_diff = k
	num_of_pairs = 0
	sum_of_two_list = []
	for j in range(n):
		for l in range(j + 1, n):
			sum_value = a[j] + a[l]
			sum_of_two_list.append(abs(sum_value - k))
	print(min(sum_of_two_list), sum_of_two_list.count(min(sum_of_two_list)))


import math
case = int(input())
for i in range(case):
	(N, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	curr_min = math.inf
	count = 0
	for i in range(N):
		for j in range(i + 1, N):
			min_value = abs(arr[i] + arr[j] - k)
			if min_value == curr_min:
				count += 1
			if min_value < curr_min:
				curr_min = min_value
				count = 1
	print(curr_min, count)


for testcase in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = list(map(int, input().split()))
	result = [abs(a[i] + a[j] - k) for i in range(0, n) for j in range(i + 1, n)]
	print(min(result), result.count(min(result)))