#include #include using namespace std; #define LL long long const int MX = 1e5 + 233; LL A[MX] ,S[2][MX]; int main(){ int T; scanf("%d" ,&T); while(T--){ int n; scanf("%d" ,&n); for(int i = 1 ; i <= n ; ++i) scanf("%lld" ,A + i); sort(A + 1 ,A + 1 + n); for(int i = 1 ; i <= n ; ++i) S[0][i] = S[0][i - 1] + A[i]; for(int i = n ; i ; --i) S[1][i] = S[1][i + 1] + A[i]; LL Ans = 0; for(int i = 1 ; i <= n ; ++i){ Ans += i * A[i] - S[0][i]; Ans += -(n - i + 1) * A[i] + S[1][i]; } printf("%lld\n" ,Ans / 2); }return 0; }