#include <bits/stdc++.h>
#include <string.h>
#include <string>

using namespace std;




int main()
{
    int t,n,i;
    long a[200002];
    long long sum;
    cin>>t;
    while(t--)
    {
        sum=0;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sum = sum + a[i];
        }
        sum = sum%n;
        sum = (n-sum) * sum;
        cout<<sum<<endl;

    }

    return 0;
}

