#pragma GCC optimize(2)
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
#define fi first
#define se second
#define y1 yy1
//const long long mx=1e11;
//const long long mod=1e9+7;
const long long mod=998244353;
const long long maxn=2e5+10;
 
long long p[2]={1000000007,998244353};
long long seed[2]={500000004,500000004};
 
int tt;
int n,m;


int main(){
	
	
	scanf("%d",&tt);
	while(tt--){
		scanf("%d",&n);
		long long sum=0,x,y;
		for(int i=0;i<n;i++){
			scanf("%d",&m);
			sum+=m;
		}
		y=sum%n;
		x=n-y;
		printf("%lld\n",x*y);
	}
	
	return 0;
}
