#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
void print(vector<long long> a) {
  for (long long i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << "\n";
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
bool cmp(long long a, long long b) { return a > b; }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long tc = 0; tc < t; tc++) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    long long i = 0, j = n - 1;
    while (i <= j) {
      long long df = a[j] - a[i];
      df /= 2;
      a[i] += df;
      a[j] -= df;
      i++, j--;
    }
    long long ans = 0, pf = 0;
    sort(a.begin(), a.end());
    for (long long i = 0; i < n; i++) {
      long long c = i * a[i] - (pf);
      ans += c;
      pf += a[i];
    }
    cout << ans << "\n";
  }
}
