#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include #define X first #define Y second #define PB push_back #define MP make_pair #define EB emplace_back #define mset(var,val) memset(var,val,sizeof(var)) #define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0) #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) //using namespace __gnu_pbds; //using namespace __gnu_cxx; using namespace std; namespace ___ { #ifdef local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { cout << endl; } template class T, typename t, typename... Args> void err(T a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); } template void err(T a, Args... args) { cout << a << ' '; err(args...); } #else #define dbg(...) #endif //#ifdef local //typedef long long LL; //#else //typedef __int128 LL; //#endif // local int _ = 0; void testcase() { cout << "Case " << (++_) << ": "; } } template inline bool scan(T&ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-' and (c<'0' or c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0' and c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template inline void out(T x) { if(x>9) out(x/10); putchar(x%10+'0'); } using namespace ___; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair pii; typedef pair pll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const double eps = 1e-6; const int mod = 998244353; const int lim = 1e3; const int N = 2e6+10; const int M = 1e6+10; #define lson (rt<<1) #define rson (rt<<1|1) ll qpow(ll a, ll b) { ll ans = 1; for(;b;b>>=1){ if(b&1) ans = ans*a%mod; a=a*a%mod; } return ans; } ll a[N]; void work(){ int n; cin >> n; rep(i,n){ cin >> a[i]; } if (n == 1) { cout << 0 << "\n"; return; } sort(a, a+n); ll pre = a[0]; int cnt = 1; ll ans = 0; for (int i = 1; i < n; ++i) { ans += a[i]*cnt - pre; pre += a[i]; cnt++; } cout << ans << "\n"; } int main() { #ifdef local freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); #endif // local IOS; // init(); int t; cin>>t; // for(; t--;) work(); // return 0; }