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

const int N = 2e5;
ll a[N];

void KhanhNgok(){
	ll n; cin >> n;
	ll sum = 0;
	for (int i=0; i<n; i++){
		cin >> a[i];
		sum += a[i];
	}
	if (sum==0){
		cout << 0 << "\n";
		return;
	}
	ll x = sum % n;
	cout << x * (n-x) << "\n";
}
 
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t; cin >> t;
	while (t--){
		KhanhNgok();
	}
 
	return 0;
}