#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) #define MEM(a,b) memset(a,b,sizeof(a)) #define MP(a,b) make_pair(a,b) #define PB push_back #define X first #define Y second typedef long long ll; typedef pair pll; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int MAXN = 100; ll C[40][40]; int T,n,A[MAXN]; int main(){ for(int i = 0; i < 40; ++i){ C[i][0] = C[i][i] = 1; for(int j = 1; j < i; ++j){ C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } } scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i = 1; i <= n; ++i){ scanf("%d",&A[i]); } sort(A + 1,A + n + 1); ll odd = 0,even = 0; for(int i = 1; i <= n; ++i){ int rem = n - i; for(int j = 0; j <= rem; j += 2){ odd += 1ll * A[i] * C[rem][j]; } for(int j = 1; j <= rem; j += 2){ even += 1ll * A[i] * C[rem][j]; } } ll ans = odd - even; if(ans < 0) ans = -ans; printf("%I64d\n",ans); } return 0; }