#include <bits/stdc++.h>
using namespace std;

#define frr(i,a,b) for(int i=a;i<=b;i++)
#define test(t) int t; cin >> t; frr(tno,1,t)
#define endl '\n'
#define int long long


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout.precision(numeric_limits<double>::max_digits10);
    test(t)
    {
        int n;
        cin >> n;
        int sum=0;
        for (int t1=0;t1<n;t1++)
        {
            int z;
            cin >> z;
            sum+=z;
        }
        sum%=n;
        cout << ((n-sum)*sum) << endl;
    }
    return 0;
}