#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPX(op, t, x) operator op(CRP(t, x))
#define OPL(t, x) bool OPX(<, t, x) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef int64_t ll, i64;
typedef uint64_t ull, u64;
template <typename... Types>
using comtype = typename common_type<Types...>::type;
template <typename T>
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
template <typename T>
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
inline char getchar(int)
{
    static char buf[64 << 20], *S = buf, *T = buf;
    if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
    return S == T ? EOF : *S++;
}
template <typename T, typename = enable_if_integral<T>>
inline bool read(T &x)
{
    int ch = x = 0, f = 1;
    while (!isdigit(ch = getchar()))
        if (ch == EOF)
            return false;
        else if (ch == '-')
            f = 0;
    for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
    return x = f ? x : -x, true;
}
template <typename T, typename... Args, typename = enable_if_integral<T>>
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
inline ll gcd(ll a, ll b)
{
    for (; b; swap(a, b)) a %= b;
    return a;
}
inline ll fpow(ll a, ll b, ll m)
{
    ll r = 1;
    for (; b; b >>= 1, a = a * a % m)
        if (b & 1) r = r * a % m;
    return r;
}
constexpr double eps = 1e-8;
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
const int N = 2e5 + 50;
int a[N], b[N];
int main()
{
    set<pair<int, int>> S;
    int T, n;
    read(T);
    while (T--)
    {
        S.clear();
        read(n);
        for (int i = 0; i < n; i++) read(a[i]);
        sort(a, a + n);
        ll sum = 0;
        for (int i = 0; i < n; i += 2)
            sum += a[i | 1] - a[i];
        sum <<= 1;
        memset(b, -1, sizeof(int) * n);
        for (int i = 0; i < n; i++) S.insert({a[i], i});
        S.erase({a[0], 0});
        S.erase({a[2], 2});
        S.erase({a[n - 1], n - 1});
        S.erase({a[n - 3], n - 3});
        b[0] = a[2], b[2] = a[0];
        b[n - 1] = a[n - 3], b[n - 3] = a[n - 1];
        for (int i = 0; i < n; i++)
            if (b[i] == -1)
            {
                bool p = false;
                auto pre = S.find({a[i ^ 1], i ^ 1});
                if (pre != S.end())
                {
                    p = true;
                    S.erase(pre);
                }
                auto t1 = S.lower_bound({a[i], i});
                auto t2 = S.upper_bound({a[i], i});
                if (t1 == S.begin())
                {
                    b[i] = a[t2->second];
                    b[t2->second] = a[i];
                    S.erase({a[i], i});
                    S.erase(t2);
                    if (p) S.insert({a[i ^ 1], i ^ 1});
                    continue;
                }
                if (t2 == S.end())
                {
                    --t1;
                    b[i] = a[t1->second];
                    b[t1->second] = a[i];
                    S.erase({a[i], i});
                    S.erase(t1);
                    if (p) S.insert({a[i ^ 1], i ^ 1});
                    continue;
                }
                --t1;
                if (a[i] - t1->first <= t2->first - a[i])
                {
                    b[i] = a[t1->second];
                    b[t1->second] = a[i];
                    S.erase({a[i], i});
                    S.erase(t1);
                }
                else
                {
                    b[i] = a[t2->second];
                    b[t2->second] = a[i];
                    S.erase({a[i], i});
                    S.erase(t2);
                }
                if (p) S.insert({a[i ^ 1], i ^ 1});
            }
        for (int i = 0; i < n; i++) sum += abs(a[i] - b[i]);
        printf("%lld\n", sum >> 1);
    }
    return 0;
}