#include<bits/stdc++.h>
#define ll long long int
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll nad()
{
	ll n,m,k,cnt=0,cnt1=0,cnt2=0,sum=0,mu=1;
	cin>>n;
	ll arra[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arra[i];
		sum+=arra[i];
	}
	cout<<(sum%n)*(n-(sum%n))<<endl;
	return 0;
}
int main()
{
	fastio;
	ll t;
	cin>>t;
	while(t--)
	{
		nad();
	}
	return 0;
}
