#include<bits/stdc++.h>
using namespace std;
#define mod        1000000007
#define pb         push_back
#define mp         make_pair
#define rep(n)     for(int i=0;i<n;i++)
#define repit(x)   for(auto it : x)
#define ll         long long
#define vi         vector<int>
#define vc         vector<char>
#define vs         vector<string>
#define mii        map<int ,int>
#define mci        map<char ,int>



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a;
        ll sum=0;
        rep(n)
        {
           cin>>a;
           sum+=a;
        }
        ll x,y;
        x=min(sum%n,n-sum%n);
        y=max(sum%n,n-sum%n);
        ll ans=x*y;
        cout<<ans<<"\n";
    }
}