#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1; char s;
	while((s=getchar())<'0'||s>'9') if(s=='-') f=-1;
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+(s^'0'),s=getchar();
	return x*f;
}
const int maxn=200005;
int n,m,t,a[maxn];
long long sum,ans;
int main(){
	t=read();
	while(t--){
		sum=0;
		n=read();
		for(register int i=1;i<=n;++i){
			a[i]=read(),sum+=a[i];
		}
		sum%=n;
		ans=sum*(n-sum);
		printf("%lld\n",ans);
	}
	return 0;
} 