#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<map>

#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define endl "\n"
#define pii pair<int,int>
#define pb push_back
#define debug(x) cout << "visit:" << x << endl
#define inf 2147483647

using namespace std;

const int N = 2e5+5;

ll a[N]={0};

int main()
{
	fast;
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		ll sum = 0;
		for(int i=1;i<=n;++i)
		{
			cin >> a[i];
			sum += a[i];
		}
		sum %= n;
		cout << (n-sum)*sum << endl;
	 } 
	return 0;
}

/***********************************************************/
/***********************************************************/
/***** A          CCCCCC       PPPPP       L       ZZZZZZ **/
/**** A A        C            P    P      L           Z  ***/
/*** A   A      C            PPPPPP      L          Z   ****/
/** AAAAAAA     C           P           L         Z    *****/
/* A       A     CCCCCC    P           LLLLL    ZZZZZZ  ****/
/***********************************************************/
/***********************************************************/
