#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll int mod = 1000000007; // 10^9+7
ll int huge = 1000000000000000000; // 10^18

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll int t = 1;
    cin>>t;

    while(t--){
        ll int n;
        cin>>n;

        ll int arr[n],sum = 0;
        for (int i = 0; i <n ; ++i) {
            cin>>arr[i];
            sum+=arr[i];
        }

        if(sum%n == 0){
            cout<<0<<"\n";
        }
        else{
            ll int val = sum/n;
            ll int rem = sum%n;
            ll int minVal = min(rem,n - rem);
            ll int maxVal = max(rem,n - rem);
            ll int ans = minVal*maxVal;
            cout<<ans<<"\n";
        }

    }

    return 0;
}