#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect import heapq import functools mod=10**9+7 import sys input=sys.stdin.readline t = int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() ans = 0 l=0 r=n-1 cnt = 0 while cnt < n: if cnt % 2 == 0: if cnt == n - 1: ans += a[l] cnt += 1 continue if a[r] - a[r-1] + a[l] >= a[l+1]: ans += a[r] - a[r-1] r -= 1 else: l += 1 else: r -= 1 cnt += 1 print(ans)