#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
int main()
{
    fast;
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll sum=0;
        ll x;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            sum+=x;
        }

        ll r=sum%n;
        cout<<r*(n-r)<<endl;
    }
}