#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define endl "\n"
const ll mod = 1e9+7;
#define fi first
#define ss second
using ii = pair<ll,ll>;
#define pb push_back
#define mp make_pair


void solve()
{
    ll n;cin>>n;
    ll a[n];
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];sum+=a[i];
    }


    ll tb = sum%n;
    ll ans = (n-tb) * tb;
    cout<<ans<<endl;




}
signed main()
{
    IOS
    int t;cin>>t;
    while(t--)
    {
        solve();
    }
}