#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long int n,i,sum=0,r;
        cin>>n;
        vector<long long>a(n);
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        r=sum%n;
       //sum=sum/n;
       cout<<(r*(n-r))<<endl;
       
        
        
        
    }
}