#include <bits/stdc++.h>
using namespace std;
#define ln '\n'
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        int a[n];
        ll sum = 0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        ll ans = 0;
        ll k = sum%n;
        ans = (k)*(n-k);
        cout<<ans<<endl;
    }
    return 0;
}