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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin>>t;
	while(t--)
	{


		ll int n;
		cin>>n;
		vector<ll int> a(n);
		ll int sum=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			sum+=a[i];
		}
		//cout<<sum<<" sum\n";

		sum%=n;
		ll int d=n-sum;
		cout<<d*sum<<"\n";


	}

}
