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

#define ll long long int

int main() {
	int t;
	cin >> t;
	while(t--){
	    ll n;
	    cin >> n;
	    vector<ll> v (n);
	    for(ll i=0;i<n;i++) cin >> v[i];
	    
	    ll sum=0;
	    for(ll i=0;i<n;i++) sum+= v[i];
	    
	    ll val= sum%n;
	    ll res= (n-val)*val;
	    
	    cout << res << endl;
	    
	}

	return 0;
}