t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    frs, scd = [], []
    for j in range(m):
        if j % 2 == 0:
            frs.append(x[j])
        else:
            scd.append(x[j])
    frs.sort()
    scd.sort()
    s_first, s_second = sum(frs), sum(scd)
    ans = s_first - s_second
    if m % 2 == 0:
        ans = max(ans, -ans)
    tmp = s_second - s_first
    lnf = len(frs)
    for j in range(lnf - 1, -1, -1):
        tmp += frs[j] * 2
        if lnf - j - 2 >= 0:
            tmp -= scd[lnf - j - 2] * 2
        ans = max(ans, tmp)
    print(ans)
