#include<bits/stdc++.h>
#define int long long
#define N 200005
using namespace std;
int t;
int n,a[N],sum;
signed main()
{
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld",&n);sum=0;
		for(int i=1;i<=n;++i)
		{scanf("%lld",&a[i]);sum+=a[i];}
		printf("%lld\n",sum%n*(n-sum%n));
	}
	return 0;
}