n = int(input())
i = 0
ans = []
while i < n :
hh = input().split()
houses = int(hh[0])
hills = int(hh[1])
coo = [int(x) for x in input().split()]
if houses == 1 and hills == 1:
q = 0
ans.append(q)
elif houses == 1 and hills%2 == 0 :
q = hills//2
ans.append(q)
elif houses == 1 and hills%2 != 0 :
q = (hills - 1)//2
ans.append(q)
else :
ma = coo[-1] - coo[0] + 1
if ma == hills :
w = 0
j = 0
while j < houses :
mo = coo[j] - coo[0]
mt = coo[j] - coo[-1]
if mo < 0 :
mo = mo*(-1)
if mt < 0 :
mt = mt * (-1)
an = max(mo,mt)
w = w + an
j += 1
ans.append(w)
elif hills > ma :
nohill = hills - ma
dis = nohill//2
rf = coo[-1] + dis
lf = coo[0] - (nohill - dis)
ww = 0
jj = 0
while jj < houses :
moo = coo[jj] - lf
mtt = coo[jj] - rf
if moo < 0 :
moo = moo*(-1)
if mtt < 0 :
mtt = mtt * (-1)
ann = max(moo,mtt)
ww = ww + ann
jj += 1
ans.append(ww)
elif hills < ma :
nohilll = ma - hills
diss = nohilll//2
rff = coo[-1] - diss
lff = coo[0] + (nohilll - diss)
www = 0
jjj = 0
while jjj < houses :
mooo = coo[jjj] - lff
mttt = coo[jjj] - rff
if mooo < 0 :
mooo = mooo*(-1)
if mttt < 0 :
mttt = mttt * (-1)
annn = max(mooo,mttt)
www = www + annn
jjj += 1
ans.append(www)
else :
aq = 2/0
print(aq)
i += 1
for rr in ans :
print(rr)