#include <bits/stdc++.h>
#define ll long long int
#define lnum vector<ll>
#define pii pair<ll,ll>
#define ld long double
#define out return 0
#define pb push_back
#define mp make_pair
#define exit exit(0)
#define pp pop_back
#define S second
#define F first
#define all(a) a.begin(),a.end()
const ll mrx=1e6+5,M=1e9+7,dm=1e3+5;
ll mx=-1e18,mn=1e18;
int T=1;
using namespace std;

void solve(){
	long long int a;
	cin>>a;
	long long int b=0,c;
	for(int i=0;i<a;i++){
		cin>>c;
		b+=c;
	}
	cout<<(b%a)*(a-(b%a))<<"\n";
}
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL), cout.tie(NULL);
	////////////////////////////////

	cin>>T;
	cout<<"\n";
	while(T--){
		solve();
	}













	out;
}
/*
      by Bekzhan Alakbayev.
*/
