/* * Author: Kewth * Date: echo -n ' ' && date +%Y.%m.%d # Type "!!sh" in Vim. * Solution: To be updated after "Accept". * Digression: * CopyRight: %%%%%%%%%%% %%%% %%%% %% %%━━■%% %% %% %% %%% %% % %% %% % %%%%■% %% %%% %% %%% %%%%%%%%%%%%%%■%% %%%%%% */ #include #include #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; static struct { inline operator int () { int x; return scanf("%d", &x), x; } inline operator ll () { ll x; return scanf("%lld", &x), x; } template inline void operator () (T &x) { x = *this; } template inline void operator () (T &x, A &...a) { x = *this; this -> operator () (a...); } } read; const int maxn = 100005; ll a[maxn]; int main () { int T = read; while (T --) { int n = read; for (int i = 1; i <= n; i ++) read(a[i]); std::sort(a + 1, a + n + 1); ll ans = 0, sum = 0; for (int i = 1; i <= n; i ++) { ans += a[i] * (i - 1) - sum; sum += a[i]; } printf("%lld\n", ans); } }