#include #include #include #include using namespace std; const int MaxN = 100000; int T, n, a[MaxN + 5]; long long suff[MaxN + 5]; int main() { scanf("%d", &T); for (int cas = 1; cas <= T; cas++) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); suff[n + 1] = 0; for (int i = n; i >= 1; i--) { suff[i] = suff[i + 1] + a[i]; //cout << suff[i] << endl; } long long ans = 0; for (int i = 1; i <= n - 1; i++) { ans = (ans + suff[i + 1] - (long long)a[i] * (n - i)); } printf("%lld\n", ans); } return 0; }