#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define vc vector
#define mt make_tuple
//fflush(stdout);
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n;
        cin>>n;
        long long tab[n];
        long long sum=0;
        for(int j=0;j<n;j++)
        {
            cin>>tab[j];
            sum+=tab[j];
        }
        long long wart =  sum%n;
        long long wynik =  wart*(n-wart);
        cout<<wynik<<endl;
    }

}