CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
import copy

N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))

a_list = sorted(a_list)


def judge(w_list, k):
    w_list = sorted(w_list)

    for i in range(len(w_list) - 1):
        w_list += [abs(w_list[i] - w_list[i + 1])]

    w_list = sorted(list(set(w_list)))

    if k in w_list:
        return True, w_list
    elif 1 in w_list:
        return True, w_list
    elif abs(w_list[0] - w_list[-1]) < K:
        return False, w_list
    elif k % 2 == 0 and 2 in w_list:
        return True, w_list
    else:
        for w in w_list:
            if w + K in w_list:
                return True, w_list

        return False, w_list


w_list = a_list

while True:
    org_w_list = copy.copy(w_list)
    is_ok, w_list = judge(w_list, K)
    if is_ok:
        break
    else:
        if abs(w_list[0] - w_list[-1]) < K:
            break
        if w_list == org_w_list:
            break

ans = "POSSIBLE" if is_ok else "IMPOSSIBLE"

print(ans)


# Optimized solution
#!/usr/bin/env python3
import copy

N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))

a_list = sorted(a_list)


def judge(w_list, k):
    w_list = sorted(w_list)

    for i in range(len(w_list) - 1):
        w_list += [abs(w_list[i] - w_list[i + 1])]

    w_list = sorted(list(set(w_list)))

    if k in w_list:
        return True, w_list
    elif 1 in w_list:
        return True, w_list
    elif abs(w_list[0] - w_list[-1]) < K:
        return False, w_list
    elif k % 2 == 0 and 2 in w_list:
        return True, w_list
    else:
        ww_list = set([w + K for w in w_list])
        if ww_list & set(w_list):
            return True, w_list
        else:
            return False, w_list


w_list = a_list

while True:
    org_w_list = copy.copy(w_list)
    is_ok, w_list = judge(w_list, K)
    if is_ok:
        break
    else:
        if abs(w_list[0] - w_list[-1]) < K:
            break
        if w_list == org_w_list:
            break

ans = "POSSIBLE" if is_ok else "IMPOSSIBLE"

print(ans)
# Original solution
"""
KがAの最大公約数の倍数であれば実現可能。そうでなければ実現不可能。
"""
import sys
sys.setrecursionlimit(200000)
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
if N ==1:
    g = A[0]
else:
    g = gcd(A[0],A[1])
    for i in range(2,N):
        g = gcd(g,A[2])

if K<=max(A) and K%g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

# Optimized solution
import sys
sys.setrecursionlimit(200000)
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
g = A[0]
for i in range(1,N):
    g = gcd(g,A[i])
if K > max(A):
    print("IMPOSSIBLE")
    exit()
if K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
# Original solution
n = int(eval(input()))
alist = [int(s) for s in input().split(" ")]

import copy
a_ans = []
for i in range(n):
  atmp = copy.copy(alist)
  del atmp[i]
  ans = atmp[0]
  for a in atmp[1:]:
    ans ^= a
  a_ans.append(ans)
print((" ".join([str(a) for a in a_ans])))

# Optimized solution
n = int(eval(input()))
alist = [int(s) for s in input().split(" ")]
asum = alist[0]
for a in alist[1:]:
  asum ^= a

import copy
a_ans = []
for i in range(n):
  asum ^= alist[i]
  a_ans.append(asum)
  asum ^= alist[i]
print((" ".join([str(a) for a in a_ans])))
# Original solution
def combine(a, j):
    # combine by xor all elements of a except a[j]
    x = 0
    n = len(a)
    for i in range(n):
        if i != j:
            x ^= a[i]
    return x

def main():
    N = int(eval(input()))
    a = [int(i) for i in input().split()]

    print((' '.join(str(combine(a, j)) for j in range(N))))


main()


# Optimized solution
def main():
    N = int(eval(input()))
    a = [int(i) for i in input().split()]
    x = 0
    for i in range(N):
        x ^= a[i]

    x ^= a[0]
    xors = [x]
    for i in range(1, N):
        x ^= a[i-1]
        x ^= a[i]
        xors.append(x)

    print((' '.join(str(x) for x in xors)))


main()
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = [None]*n

for i in range(n):
    buf = 0
    for j in range(n):
        if i != j:
            buf = buf^a[j]
    ans[i]=str(buf)
print((' '.join(ans)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = [None]*n
all = 0

for i in range(n):
    all = all^a[i]

for i in range(n):
    ans[i]=str(all^a[i])
print((' '.join(ans)))
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]


ans = []
for i in range(n):
    temp = 0
    for j, aa in enumerate(a):
        if j == i:
            continue
        temp = temp ^ aa
    ans.append(temp)

ans = [str(i) for i in ans]
print((" ".join(ans)))


# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]


ans = []
alld = 0

for aa in a:
    alld = alld ^ aa

for  aa in a:
    ans.append(alld ^ aa)

ans = [str(i) for i in ans]
print((" ".join(ans)))
# Original solution
N = int(eval(input()))
a = [int(s) for s in input().split()]
b = a[0]
c = str("")
for i in range(1,N):
  b = b ^ a[i]
c = str(b ^ a[0])
for i in range(1, N):
  c = c + " " + str(b ^ a[i])
print(c)

# Optimized solution
N = int(eval(input()))
a = [int(s) for s in input().split()]
b = a[0]
c = []
for i in range(1,N):
  b = b ^ a[i]

for i in range(N):
  c.append(str(b ^ a[i]))
 
d = ' '.join(c)

print(d)
# Original solution
import copy
N = int(eval(input()))
A = list(map(int,input().split()))

result = ['' for _ in range(N)]

for i in range(N//2):
    if i < N -2:
        s_1 = A[2*i+1]
        s_2 = A[2*i]
        for j in range(2*i+2, N):
            s_1 = s_1 ^ A[j]
            s_2 = s_2 ^ A[j]
        result[2*i] = str(s_1)
        result[2*i+1] = str(s_2)
        m = s_1^s_2
        for j in range(2*i+2, N):
            A[j] = m^A[j]
 
    else:
        result.append(str(A[N-1]))
        result.append(str(A[N-2]))
        break

print((' '.join(result)))

# Optimized solution
import copy
N = int(eval(input()))
A = list(map(int,input().split()))

result = ['' for _ in range(N)]
s = A[0]
for i in range(1,N):
    s = s ^ A[i]

for i in range(N):
    result[i] = str(s ^ A[i])

print((' '.join(result)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
maxl = len(bin(max(A))[2:])
ans = [['0'] * N for _ in range(maxl)]
for n in range(N):
    for d, a in enumerate(bin(A[n])[2:].zfill(maxl)):
        ans[d][n] = a

for dn in range(maxl):
    n1 = sum([1 for d in ans[dn] if d == '1'])
    if n1 % 2 == 1:
        for n in range(N):
            ans[dn][n] = '0' if ans[dn][n] == '1' else '1'

prt = [int(''.join([ans[d][n] for d in range(maxl)]), 2) for n in range(N)]
print((' '.join(map(str, prt))))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
S = 0
for a in A:
    S ^= a
print((" ".join([str(S ^ a) for a in A])))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = []
x = sum(a)
for i in range(n):
    m = 0
    for j in range(n):
        if i == j:
            pass
        else:
            m = m ^ a[j]
    b.append(m)
b = list(map(str,b))
print((' '.join(b)))

# Optimized solution
import time
start = time.time()
n = int(eval(input()))
a = list(map(int,input().split()))
b = []
m = 0
for i in range(1,n):
    m = m ^ a[i]
b.append(m)
for j in range(1,n):
    m = m ^ a[j-1]
    m = m ^ a[j]
    b.append(m)
b = list(map(str,b))
print((' '.join(b)))
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
pari = [0] * 40
for i in range(40):
    for j in a:
        pari[i] += (j&(1<<i))>>i

ans = a[:]

for i in range(40):
    if pari[i]%2:
        for j in range(n):
            if a[j]&(1<<i):
                ans[j] -= 1<<i
            else:
                ans[j] += 1<<i

print((' '.join([str(i) for i in ans])))

# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
pari = [0] * 30
for i in range(30):
    for j in a:
        pari[i] += (j&(1<<i))>>i

ans = a[:]

for i in range(30):
    if pari[i]%2:
        for j in range(n):
            if a[j]&(1<<i):
                ans[j] -= 1<<i
            else:
                ans[j] += 1<<i

print((' '.join([str(i) for i in ans])))
# Original solution
n = int(eval(input()))
a_list = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
    for j,a in enumerate(a_list):
        if j != i:
            ans[i]=ans[i]^a
ans = " ".join([str(i) for i in ans])
print(ans)

# Optimized solution
n = int(eval(input()))
a_list = list(map(int, input().split()))
base_xor = 0
for i in a_list:
    base_xor = base_xor^i
ans = [0]*n
for i in range(n):
    ans[i] = a_list[i]^base_xor
ans = " ".join([str(i) for i in ans])
print(ans)
# Original solution
n = int(eval(input()))
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
    scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print((" ".join(str(x) for x in scarf_val)))

# Optimized solution
n = int(eval(input()))
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print((" ".join(str(x) for x in scarf_val)))
# Original solution
N=int(eval(input()))
a=list(map(int,input().split()))
b=a[0]
for i in range(N-1):
  b=b^a[i+1]
ans=""
for i in range(N):
  if(i<N-1):
    ans+=str(b^a[i])+" "
  else:
    ans+=str(b^a[i])
print(ans)

# Optimized solution
N=int(eval(input()))
a=list(map(int,input().split()))
b=a[0]
for i in range(N-1):
  b=b^a[i+1]
x=[0 for i in range(N)]
for i in range(N):
  x[i]=b^a[i]
x=list(map(str,x))
ans=' '.join(x)
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
ref=[0 for _ in range(mx-2)]
for j in range(n):
    work=b[j]
    for i in range(mx-2):
        ref[i]+=int(work[i])
        ref[i]%=2

for j in range(n):
    work=b[j]
    for i in range(mx-2):
        if int(work[i])==ref[i]:out[j]+="0"
        else : out[j]+="1"

c=[str(int(y,2)) for y in out]
print((" ".join(c)))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
for i in range(mx-2):
    tot=0
    for j in range(n):
        tot+=int(b[j][i])
    tot=tot%2
    for j in range(n):
        if tot==int(b[j][i]):out[j]+="0"
        else : out[j]+="1"
c=[str(int(y,2)) for y in out]
print((" ".join(c)))
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))

ans = []
for i in range(n):
    tmp = 0
    for j in range(n):
        if i==j:
            continue
        tmp=A[j]^tmp
    ans.append(tmp)
print((' '.join(map(str,ans))))

# Optimized solution
n = int(eval(input()))
A = list(map(int,input().split()))

xor_sum = 0
for i in range(n):
    xor_sum = xor_sum^A[i]

ans = []
for i in range(n):
    ans.append(xor_sum^A[i])
print((' '.join(map(str,ans))))
# Original solution
def main():
    n = int(eval(input()))
    a = list(map(int,input().split()))
    l = len(format(max(a),'b'))
    a = [format(a[i],'0{}b'.format(l)) for i in range(n)]
    ans = [[] for i in range(n)]
    for i in range(l):
        s = 0
        for j in range(n):
            s+=int(a[j][i])
        if s%2!=0:
            for j in range(n):
                ans[j].append(str((int(a[j][i])+1)%2))
        else:
            for j in range(n):
                ans[j].append(a[j][i])
    for i in range(n):
        ans[i] = ''.join(ans[i])
        ans[i] = str(int(ans[i],2))
    print((' '.join(ans)))

if __name__ == "__main__":
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    a = list(map(int,input().split()))
    b = a[0] ^ a[1]
    for i in range(2,n):
        b = b ^ a[i]
    ans = []
    for i in range(n):
        ans.append(b ^ a[i])
    ans = list(map(str,ans))
    print((' '.join(ans)))

if __name__ == "__main__":
    main()
# Original solution
from functools import reduce

N = int(input().strip())
A = [int(x) for x in input().strip().split(" ")]

# def calc(A, i):

values = [
    str(reduce(lambda x, y: x ^ y, [v[1] for v in [v for v in enumerate(A) if v[0] != i]]))
    # calc(A, i)
    for i in range(len(A))
]
print((" ".join(values)))

# Optimized solution
from functools import reduce

N = int(input().strip())
A = [int(x) for x in input().strip().split(" ")]
xor = reduce(lambda x, y: x ^ y, A)

print((" ".join([
    str(xor ^ a)
    for a in A
])))
# Original solution
n = int(eval(input()))
a = list(map(int , input().split()))
b = []
for ai in a:
    b.append('{:0=30b}'.format(ai))

cnt = []
for j in range(30):
    tmp = 0
    for i in range(n):
        tmp += int(b[i][j])
    cnt.append(tmp)
ans = []
for bi in b:
    tmp = 0
    for i in range(30):
        idx = 29 + (-i)
        #print(idx)
        x = int(bi[i])
        if cnt[i] == 0:
            continue
        if cnt[i] % 2 == 0:
            tmp += x << idx
        else:
            if x == 0:
                tmp += 1 << idx
    ans.append(tmp)


#print(ans)
print((' '.join(map(str, ans))))

"""
0000010100
0000001011
0000001001
0000011000

0000011010
0000000101
0000000111
0000010110
"""

# Optimized solution
n = int(eval(input()))
a = list(map(int , input().split()))
b = []
s = 0
for ai in a:
    s ^= ai
ans = []
for ai in a:
    ans.append(s ^ ai)

print((' '.join(map(str, ans))))
# Original solution
# -*- coding: utf-8 -*-


def cal_xor(xor_list, rm_ind):
    ans = None
    for i, xi in enumerate(xor_list):
        if i!=rm_ind:
            if ans is not None:
                ans = ans^xi
            else:
                ans = xi
    return ans

N, = list(map(int, input().split()))
a = list(map(int, input().split()))

ans_str = ''

if N==2:
    print(("{} {}".format(a[1], a[0])))
else:

    xors = []
    for i in range(N//2):
        xors.append(a[2*i]^a[2*i+1])

    for i, ai in enumerate(a):
        sum_xor = cal_xor(xors, i//2)
        if i%2==0:
            ind = i+1
        else:
            ind = i-1

        ans = sum_xor^a[ind]
        ans_str += str(ans)+' '
    print((ans_str[:-1]))


# Optimized solution
# -*- coding: utf-8 -*-


def cal_xor(xor_list):
    ans = None
    for xi in xor_list:
        if ans is not None:
            ans = ans^xi
        else:
            ans = xi
    return ans

N, = list(map(int, input().split()))
a = list(map(int, input().split()))

ans_str = ''

if N==2:
    print(("{} {}".format(a[1], a[0])))
else:

    xors = []
    for i in range(N//2):
        xors.append(a[2*i]^a[2*i+1])

    sum_xor = cal_xor(xors)
    for i, ai in enumerate(a):
        tmp_xor = sum_xor^xors[i//2]
        if i%2==0:
            ind = i+1
        else:
            ind = i-1

        ans = tmp_xor^a[ind]
        ans_str += str(ans)+' '
    print((ans_str[:-1]))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))

ans = [0] * N
bit = 0
for i in range(1, N):
    ans[i] = a[i - 1] ^ a[i] ^ ans[i - 1]
    bit ^= ans[i]

if bit == a[0]:
    print((' '.join(map(str, ans))))
else:
    index = 0
    for i in range(1, 10 ** 9 + 1):
        bit = bit ^ (i - 1) ^ i
        if bit == a[0]:
            index = i
            break

    ans[0] = index
    for i in range(1, N):
        ans[i] = a[i - 1] ^ a[i] ^ ans[i - 1]
        bit ^= ans[i]

    print((' '.join(map(str, ans))))


# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
S = 0
for i in range(N):
    S ^= a[i]

ans = [0] * N

for i in range(N):
    ans[i] = S ^ a[i]

print((' '.join(map(str, ans))))
# Original solution
from collections import deque
def calcXor(nums):
  x=0
  for n in nums:
    x=x^n
  return x

N=int(eval(input()))
A=list(map(int,input().split()))
ans=deque()
for i in range(N):
  #print(A[0:i])
  x=calcXor(A[0:i])
  #print(A[i+1:N])
  y=calcXor(A[i+1:N])
  ans.append(x^y)
print((" ".join(map(str,ans))))



# Optimized solution
from collections import deque
def calcXor(nums):
  x=0
  for n in nums:
    x=x^n
  return x

N=int(eval(input()))
A=list(map(int,input().split()))
A_xor=calcXor(A)

ans=deque()
for a in A:
  ans.append(A_xor^a) 

#for i in range(N):  
  #print(A[0:i])
  #x=calcXor(A[0:i])
  #print(A[i+1:N])
  #y=calcXor(A[i+1:N])
  #ans.append(x^y)
print((" ".join(map(str,ans))))
# Original solution
def mi(): return list(map(int,input().split()))
def lmi(): return list(map(int,input().split()))
def ii(): return int(eval(input()))
def isp(): return input().split()



n=ii()
a=lmi()
S=0
for i in a:
  S=S^i

b=[]
for i in a:
  a_=S^i
  b.append(a_)

print((' '.join(map(str,b))))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))

s=0
for i in a:
  s^=i
 
t=[]
for i in a:
  t_=i^s
  t.append(t_)
  
print((' '.join(map(str,t))))
# Original solution
n = int(eval(input()))
a = input().split()
l = [0] * 30
for i in range(n):
	a[i] = format(int(a[i]), "030b")
	for j in range(30):
		l[j] += int(str(a[i])[j])
for i in range(30):
	l[i] = l[i] % 2
b = ""
for i in range(30):
	b += str(l[i])
b = int(b, 2)
for i in range(n):
	a[i] = b ^ int(a[i], 2)
print((" ".join(map(str, a))))

# Optimized solution
n = int(eval(input()))
a = input().split()
l = 0
for i in range(n):
	a[i] = int(a[i])
	l = l ^ a[i]
for i in range(n):
	a[i] = l ^ a[i]
print((" ".join(map(str, a))))
# Original solution
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(eval(input()))


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(eval(input()))
    a_list = input_to_int_tuple()

    ret = ""
    for i in range(n):
        my = 0
        for j, v in enumerate(a_list):
            if i == j:
                continue

            my ^= v

        ret += str(my) + " "

    print((ret.rstrip()))


if __name__ == "__main__":
    main()


# Optimized solution
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(eval(input()))


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(eval(input()))
    a_list = input_to_int_tuple()

    all = 0
    for v in a_list:
        all ^= v

    ret = ""
    for v in a_list:
        ret += str(all ^ v) + " "

    print((ret.rstrip()))


if __name__ == "__main__":
    main()
# Original solution
n=int(input())
A=list(map(int,input().split()))
L = []
x=0
for a in A:
    x ^= a
    L.append(x)
R = []
x=0
for a in reversed(A):
    x ^= a
    R.insert(0, x)
for i in range(n):
    x = 0
    if i>0:
        x^=L[i-1]
    if i<n-1:
        x^=R[i+1]
    print(x, end="")
    if i==n-1:
        print("")
    else:
        print(" ",end="")


# Optimized solution
n=int(input())
A=list(map(int,input().split()))
L = []
x=0
for a in A:
    x ^= a
    L.append(x)
R = []
x=0
for a in reversed(A):
    x ^= a
    R.append(x)
for i in range(n):
    x = 0
    if i>0:
        x^=L[i-1]
    if i<n-1:
        x^=R[n-1-(i+1)]
    print(x, end="")
    if i==n-1:
        print("")
    else:
        print(" ",end="")
# Original solution
n = int(input())
a = list(map(int, input().strip().split()))

m = len(bin(max(a))[2:])
t = [0] * (m)

for i in range(n):
    bin_str_i = [int(s) for s in list(bin(a[i])[2:])]
    l = len(bin_str_i)
    for j in range(l):
        t[m - j - 1] += bin_str_i[l - j - 1]
x = ''
for j in range(m):
    if t[j] % 2 == 0:
        x += '0'
    else:
        x += '1'

x = int(x, 2)
for i in range(n):
    ans = a[i] ^ x
    if i < n - 1:
        print(ans,end=' ')
    else:
        print(ans)



# Optimized solution
n = int(input())
a = list(map(int, input().strip().split()))

x = 0
for i in range(n):
    x = x ^ a[i]
#print(bin(c))


#x = int(x, 2)
for i in range(n):
    ans = a[i] ^ x
    if i < n - 1:
        print(ans,end=' ')
    else:
        print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
m = max(a)
count = 0
nishin = []

while True:
    m, r = divmod(m, 2)
    count += 1
    if m == 0:
        break

for i in range(0, N):
    for j in range(0, count):
        a[i], r = divmod(a[i], 2)
        nishin.append(str(r))
    a[i] = ''.join(reversed(nishin))
    nishin.clear()

for k in range(0, N):
    q = ''
    for j in range(0, count):
        p = 0
        for i in range(0, N):
            if i == k:
                pass
            else:
                p += int(a[i][j])
        p %= 2
        q += str(p)
    nishin.append(q)

jusshin = [int(i, 2) for i in nishin]

ans = ''

for i in range(0, N-1):
    ans += (str(jusshin[i]) + ' ')

ans += str(jusshin[N-1])
print(ans)


# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
x = 0
for i in range(0, N):
    x ^= a[i]
ans = []
for i in range(0, N):
    ans.append(str(x ^ a[i]))

print((' '.join(ans)))
# Original solution
n=int(eval(input()))
A=list(map(int,input().split()))
ans=[]
for i in range(n):
    l=A[:i]+A[i+1:]
    sum=0
    for a in l:
        sum=sum^a
    ans.append(sum)
ans=' '.join(map(str,ans))
print(ans)

# Optimized solution
n=int(eval(input()))
A=list(map(int,input().split()))
ans=[]
sum=0
for a in A:
    sum=sum^a
for a in A:
    ans.append(sum^a)
ans=' '.join(map(str,ans))
print(ans)
# Original solution
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
TLE
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    t = int(eval(input()))
    for _ in range(t):
        n, k = list(map(int, input().split()))
        houses = [int(x) for x in input().split()]

        if k >= n:              #  ????????¨?????????????????¨?????§??????
            print((0))
            continue

        diff = []
        prev = houses[0]
        for h in houses[1:]:
            temp = h - prev
            diff.append(temp)
            prev = h



        points = []
        s_diff = sorted(diff)
        for x in range(k-1):
            pos = diff.index(s_diff.pop())
            points.append(pos)
            diff[pos] = -1


        cable_total = 0
        prev = 0
        for p in points:
            cable_total += houses[p] - houses[prev]
            prev = p + 1
        if prev != (n - 1):
            cable_total += houses[-1] - houses[prev]

        print(cable_total)


if __name__ == '__main__':
    main(sys.argv[1:])

# Optimized solution
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104

"""
import sys
from sys import stdin
from bisect import bisect_left
input = stdin.readline


def main(args):
    t = int(eval(input()))
    for _ in range(t):
        n, k = list(map(int, input().split()))
        houses = [int(x) for x in input().split()]

        if k >= n:              #  ????????¨?????????????????¨?????§??????
            print((0))
            continue


        diff = []
        prev = houses[0]
        for i, h in enumerate(houses[1:]):
            diff.append((h - prev, i))
            prev = h


        diff.sort(reverse=True)
        points = diff[:k-1]


        cable_total = 0
        prev = 0
        for _, p in points:
            cable_total += houses[p] - houses[prev]
            prev = p + 1
        if prev != (n - 1):
            cable_total += houses[-1] - houses[prev]

        print(cable_total)


if __name__ == '__main__':
    main(sys.argv[1:])