#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll arr[n];
		ll sum=0;
		for(ll i=0;i<n;i++)
		{
			cin>>arr[i];
			sum+=arr[i];
		}
		ll r=sum%n;
		cout<<r*(n-r)<<endl;
	}
}