Chef has an array A of size N and an integer M, such that 1 ≤ A_{i} ≤ M for every 1 ≤ i ≤ N.

The *distance* of an array B from array A is defined as:

d(A, B) = \sum_{i=1}^N |A_{i} - B_{i}|

Chef wants an array B of size N, such that 1 ≤ B_{i} ≤ M and the value d(A, B) is as large as possible, i.e, the distance of B from A is maximum.

Find the maximum distance for any valid array B.

Note: |X| denotes the absolute value of an integer X. For example, |-4| = 4 and |7| = 7.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers N and M — the length of array A and the limit on the elements of A and B.
- The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}.

------ Output Format ------ 

For each test case, output on a new line the maximum distance of an array from A.

------ Constraints ------ 

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 2\cdot 10^{5}$
$1 ≤ M ≤ 10^{9}$
$1 ≤ A_{i} ≤ M$
- The sum of $N$ over all test cases won't exceed $3\cdot 10^{5}$.

----- Sample Input 1 ------ 
4
2 6
3 5
4 1
1 1 1 1
5 7
2 3 4 5 6
7 24
23 7 6 16 12 4 24

----- Sample Output 1 ------ 
7
0
21
127

----- explanation 1 ------ 
Test case $1$: The array having maximum distance from $A$ is $B = [6, 1]$. Thus the distance is $|3-6| + |5-1| = 3+4=7$.

Test case $2$: The only array possible is $B = [1,1,1,1]$. The distance of this array from $A$ is $0$.

Test case $3$: One of the possible arrays having maximum distance from $A$ is $B = [7,7,1,1,1]$. Thus the distance is $|2-7| + |3-7| + |4-1| + |5-1| + |6-1| = 5+4+3+4+5=21$.

Difficulty: EASY

Starter code:

Solutions:
T = int(input())
for i in range(0, T):
	(N, M) = map(int, input().split())
	n = 0
	A = list(map(int, input().split()))
	for x in range(0, N):
		if abs(A[x] - M) > abs(A[x] - 1):
			n = n + abs(A[x] - M)
		else:
			n = n + abs(A[x] - 1)
	print(n)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	for i in a:
		if abs(1 - i) > abs(m - i):
			c += abs(1 - i)
		else:
			c += abs(i - m)
	print(c)


t = int(input())
for x in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	for i in a:
		if m - i > i - 1:
			sum += m - i
		else:
			sum += i - 1
	print(sum)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum = sum + max(abs(a[i] - m), abs(a[i] - 1))
	print(sum)


for _ in range(int(input())):
	(x, maxr) = map(int, input().split())
	arr1 = [int(x) for x in input().split()]
	sum1 = 0
	for y in arr1:
		if maxr - y > y - 1:
			sum1 += maxr - y
		else:
			sum1 += y - 1
	print(sum1)


for i in range(int(input())):
	(N, L) = map(int, input().split())
	li = list(map(int, input().split()))
	Ans = 0
	for i in li:
		if i > L // 2:
			Ans += i - 1
		else:
			Ans += L - i
	print(Ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = []
	for i in A:
		if i > m // 2:
			B.append(1)
		else:
			B.append(m)
	s = 0
	for i in range(n):
		s = s + abs(A[i] - B[i])
	print(s)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = m / 2
	count = 0
	for i in a:
		if i > x:
			count += abs(i - 1)
		else:
			count += abs(m - i)
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	k = []
	for i in range(n):
		k.append(max(abs(m - l[i]), abs(1 - l[i])))
	print(sum(k))


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	a.sort()
	for i in a:
		if i <= m // 2:
			ans += abs(i - m)
		else:
			ans += abs(i - 1)
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	sum = 0
	for num in a:
		if num <= m // 2:
			sum = sum + abs(num - m)
		else:
			sum = sum + abs(num - 1)
	print(sum)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [int(j) for j in input().split()]
	ans = 0
	for j in range(n):
		ans = ans + max(abs(arr[j] - 1), abs(arr[j] - m))
	print(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	for i in range(a):
		if b - l[i] >= l[i] - 1:
			c += b - l[i]
		else:
			c += l[i] - 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = [m if abs(x - m) > abs(x - 1) else 1 for x in A]
	summ = 0
	for i in range(len(A)):
		summ += abs(A[i] - B[i])
	print(summ)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	b = list(map(int, input().split()))
	sum = 0
	for j in range(n):
		if m - b[j] >= b[j] - 1:
			sum = sum + m - b[j]
		else:
			sum = sum + b[j] - 1
	print(sum)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	y = list(map(int, input().split()))
	n = [1, b]
	avg = (1 + b) / 2
	sum = 0
	for val in y:
		if val > avg:
			sum = sum + abs(n[0] - val)
		else:
			sum = sum + abs(n[1] - val)
	print(sum)


for _ in range(int(input())):
	(number, M) = list(map(int, input().split()))
	l1 = list(map(int, input().split()))
	c = 0
	for i in l1:
		if i <= M // 2:
			c = c + abs(i - M)
		else:
			c = c + abs(i - 1)
	print(c)


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()[:n]))
	b = []
	k = 0
	for i in a:
		k1 = abs(i - m)
		k2 = abs(1 - i)
		if k1 > k2:
			b.append(m)
		else:
			b.append(1)
	for i in range(n):
		r = abs(a[i] - b[i])
		k = k + r
	print(k)


for i in range(int(input())):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	c = 0
	for i in A:
		if i <= M // 2:
			c = c + abs(i - M)
		else:
			c = c + abs(i - 1)
	print(c)


t = int(input(''))
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for j in range(len(a)):
		s += max(abs(a[j] - 1), abs(a[j] - m))
	print(s)


for T in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	maxSum = 0
	for x in a:
		if x > m // 2:
			maxSum += x - 1
		else:
			maxSum += m - x
	print(maxSum)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split(' '))
	a = list(map(int, input().split()))
	s = m // 2
	su = 0
	for i in a:
		if i <= s:
			su = su + abs(i - m)
		else:
			su = su + abs(i - 1)
	print(su)


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


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	b = []
	m1 = m // 2
	for i in range(n):
		if a[i] <= m1:
			b.append(m)
		else:
			b.append(1)
	for i in range(n):
		s = s + abs(a[i] - b[i])
	print(s)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		max1 = max(abs(l[i] - 1), abs(l[i] - m))
		l1.append(max1)
	print(sum(l1))


for i in range(int(input())):
	x = input().split()
	v = input().split()
	l = int(x[1])
	n = 0
	for i in v:
		m = 0
		i = int(i)
		b = i - 1
		if b < 0:
			b = b * -1
		if b > m:
			m = b
		b = i - int(x[1])
		if b < 0:
			b = b * -1
		if b > m:
			m = b
		n = n + m
	print(n)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	r = 0
	for i in range(n):
		if l[i] <= m // 2:
			r = r + abs(l[i] - m)
		else:
			r = r + abs(l[i] - 1)
	print(r)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	m = y // 2
	r = 0
	for j in range(len(l)):
		if l[j] <= m:
			r += abs(l[j] - y)
		else:
			r += abs(l[j] - 1)
	print(r)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		ans += max(abs(a[i] - 1), abs(a[i] - m))
	print(ans)


for o in range(int(input())):
	(n, m) = list(map(int, input().split()))
	alist = list(map(int, input().split()))
	blist = []
	for i in alist:
		if i / m <= 0.5:
			blist.append(m)
		else:
			blist.append(1)
	out = 0
	for (a, b) in zip(alist, blist):
		out += abs(a - b)
	print(out)


def sol(n, m, a):
	e = m // 2
	s = 0
	r = 0
	for k in a:
		if k > e:
			s = s + (k - 1)
		else:
			r = r + abs(k - m)
	return s + r
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(sol(n, m, a))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	b = []
	for i in arr:
		k = m - i
		d = abs(1 - i)
		b.append(max(d, k))
	print(sum(b))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in a:
		k = m - i
		d = abs(1 - i)
		b.append(max(d, k))
	print(sum(b))


t = int(input())
for i in range(t):
	conditions = input().split(' ')
	arr_A = input().split(' ')
	d_max = 0
	for j in range(int(conditions[0])):
		d_max += max(abs(int(arr_A[j]) - 1), abs(int(arr_A[j]) - int(conditions[1])))
	print(d_max)


t = int(input())
while t != 0:
	t = t - 1
	(n, m) = map(int, input().split())
	l = [int(i) for i in input().split()]
	final = 0
	for i in range(n):
		ans1 = abs(l[i] - m)
		ans2 = abs(l[i] - 1)
		final += max(ans1, ans2)
	print(final)


t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for j in range(n):
		s += max(m - a[j], a[j] - 1)
	print(s)


for i in range(int(input())):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	s = 0
	for j in A:
		s = s + max(M - j, j - 1)
	print(s)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	count = 0
	for j in range(len(a)):
		maxs = m - a[j]
		mins = a[j] - 1
		if maxs > mins:
			count += maxs
		else:
			count += mins
	print(count)


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in a:
		s = max(abs(m - i), abs(1 - i)) + s
	print(s)


for j in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = 0
	for i in range(a):
		if c[i] <= b / 2:
			d += abs(c[i] - b)
		else:
			d += abs(c[i] - 1)
	print(d)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	k = 0
	for i in range(n):
		if a[i] <= m / 2:
			k += abs(a[i] - m)
		else:
			k += abs(a[i] - 1)
	print(k)


T = int(input())
for x in range(T):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	c.sort()
	d = min(c)
	e = min(1, d)
	f = 0
	for i in c:
		x = abs(i - b)
		y = abs(i - e)
		if x >= y:
			f = f + x
		else:
			f = f + y
	print(f)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	mid = m // 2
	dist = 0
	for i in range(n):
		if a[i] > mid:
			dist += abs(a[i] - 1)
		else:
			dist += abs(a[i] - m)
	else:
		print(dist)


for _ in range(int(input())):
	(n, m) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))[:n]
	count = 0
	if m == 1:
		for i in range(len(a)):
			count += a[i] - m
		print(count)
	else:
		for i in range(len(a)):
			if a[i] <= m // 2:
				count += m - a[i]
			else:
				count += a[i] - 1
		print(count)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	c = 0
	arr = list(map(int, input().split()))
	for i in arr:
		if i > y / 2:
			c += i - 1
		else:
			c += y - i
	print(c)


a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	sum = 0
	for i in l:
		if i > y // 2:
			sum = sum + abs(i - 1)
		else:
			sum = sum + abs(i - y)
	print(sum)


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr1 = []
	arr2 = []
	arr3 = []
	sum = 0
	for i in range(n):
		arr1.append(abs(arr[i] - 1))
		arr2.append(abs(m - arr[i]))
	for i in range(n):
		if arr1[i] >= arr2[i]:
			arr3.append(1)
		else:
			arr3.append(m)
	for i in range(n):
		sum = sum + abs(arr[i] - arr3[i])
	print(sum)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	y = min(li)
	y = min(1, y)
	tot = 0
	for item in li:
		d1 = abs(item - m)
		d2 = abs(item - y)
		if d1 >= d2:
			tot += d1
		else:
			tot += d2
	print(tot)


import math
for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	r = math.ceil(m / 2)
	count = 0
	for x in l:
		if m - x >= r:
			count += m - x
		else:
			count += x - 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	l = list(map(int, input().split()))
	for e in l:
		ans += max(abs(e - 1), abs(e - m))
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = input()
	li = s.split()
	li = [int(i) for i in li]
	sum1 = 0
	for i in range(n):
		if li[i] <= m / 2:
			sum1 = sum1 + abs(li[i] - m)
		else:
			sum1 = sum1 + abs(li[i] - 1)
	print(sum1)


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	B = 0
	for i in range(N):
		B += max(abs(A[i] - 1), abs(A[i] - M))
	print(B)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = []
	for i in range(a):
		d.append(max(abs(c[i] - 1), abs(c[i] - b)))
	print(sum(d[:]))