#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int n,a[N],sum=0,tmp;
void solve(){
	cin>>n,sum=0;
	for(int i=1;i<=n;++i) scanf("%lld",&a[i]);
	for(int i=1;i<=n;++i) sum+=a[i];
	tmp=sum%n,sum/=n;
	printf("%lld\n",tmp*(n-tmp));
}
signed main(){
	int T;cin>>T;
	while(T--) solve();
}