#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<int> v(n);
f(i, n) cin >> v[i];
sort(all(v));
int s = v[n - 1] - v[n - 2];
if (n == 2 or v[n - 3] < 0)
cout << s << endl;
else
{
int res = s;
s += v[n - 3];
if (n > 4)
s -= v[n - 4];
res = min(res, s);
cout << res << endl;
}
}
}