#include<bits/stdc++.h>
using namespace std;

typedef unsigned long long int ll;

ll a,b,c,t,n,x,sum;

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

#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

cin>>t;
while(t--){
    sum=0;
cin>>n;
for(ll i=0;i<n;i++)
{
    cin>>x;
    sum+=x;
}
x=sum%n;
ll y=n-x;
cout<<x*y<<"\n";
}








    return 0;
}