https://ac.nowcoder.com/acm/contest/76795/B
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define pb(i) push_back(i)
#define int long long
#define INF 0x3f3f3f3f
#define oz 998244353
//#define endl '\n'
#define N 200010
const int mod = 1e9 + 7;
int p[N], si[N];
int find(int x) {
if (x != p[x]) p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
void solve() {
int n;
cin >> n;
VI a(n + 1);
rep(i, 1, n)cin >> a[i];
sort(a.begin() + 1, a.end());
int x = 0, res = a[n];
rep(i, 1, n - 1) {
a[i] += x;
if (a[i] < 0) {//判断当先数在前面负数累加后是否为负数
res += a[i];
x += a[i]; //负数的贡献累加
}
else res += a[i];
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T --)
solve();
return 0;
}