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

 
typedef long long ll; 
typedef long double lld;
typedef unsigned long long ull;

 
//ll n, m, q, k, l, r, x, y, z;
const ll template_array_size = 1e6 + 16614;
// ll a[template_array_size];
// ll b[template_array_size];
// ll c[template_array_size];
// string s, t;
 

void solve(int tc = 0) {
	
	ll n,x;
	cin>>n;
	ll sum=0;
	for(int i=0;i<n;++i)
	{
		cin>>x;
		sum+=x;

	}
	sum%=n;
	cout<<sum*(n-sum)<<endl;

	
}
 
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
	
		
	int tc = 1;
	cin >> tc; 	
	for (int t = 0; t < tc; t++) solve(t);

	
	return 0;

}