#include <bits/stdc++.h>

using namespace std;

//----------------------------------------------------------------------------//

#define ll         long long int
#define ull        unsigned long long int
#define ld         long double
#define endl       '\n'
#define ff         first
#define ss         second
#define pb         push_back
#define mod        1000000007
#define vint       vector<int>
#define vll        vector<ll>
#define vchar      vector<char>
#define vstr       vector<string>
#define vvll       vector<vector<ll>>
#define vvint      vector<vector<int>>
#define pll        pair<ll,ll>
#define pint       pair<int,int>
#define all(v)     v.begin(),v.end()
#define f(i,x,n)   for(ll i=x;i<n;i++)
#define fo(i,x,n)  for(ll i=x;i>=n;i--)
#define take(a)    for(auto &i:a)cin>>i;
#define print(a)   for(auto i:a)cout<<i<<" ";
#define maxim(a)   *max_element(a.begin(),a.end())
#define minim(a)   *min_element(a.begin(),a.end())
#define prec(n,x)  cout<<fixed<<setprecision(x)<<n
#define srt(x)     sort(x.begin(),x.end())
#define rev_srt(x) sort(x.begin(),x.end(),greater<ll>())
#define fast       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//----------------------------------------------------------------------------//

template <typename T>
void out(T a)
{cout<<a<<'\n';}

void solve()
{   
    ll n;cin>>n;

    vll v(n);take(v);

    ll sum=0;

    f(i,0,n)
        sum+=v[i];

    ll ans = (sum%n)*(n- sum%n);

    cout<<ans<<endl;
}       

/****************************************************************************/

int main()
{

#ifndef ONLINE_JUDGE
    freopen("G:/Programming/CPP/input.txt", "r", stdin);
    freopen("G:/Programming/CPP/output.txt", "w", stdout);
#endif

    fast;

    ll t=1;
    cin>>t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}

