#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

typedef long long LL;

const int N = 200010;

int a[N];

int main()
{
    int T;
    cin >> T;
    
    while(T --)
    {
    	int n;
		LL sum = 0;
    	cin >> n;
    	for(int i = 0; i < n; i ++)
		{
			scanf("%d", &a[i]);
			sum += a[i];
		} 
    	int t = sum % n;
    	printf("%lld\n", (LL)(n - t) * t);
	}
	return 0;
}