#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include <unordered_map>
#include<climits>
#include<set>
#include <iomanip>
#include<numeric>
#include<queue>
#include<stack>
#include <map>
#include<bitset>
using namespace std;
#define ll long long
#define endl "\n"
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,x;
        cin>>n;
        ll sum=0;
        for(ll i=0;i<n;i++)
        {
            cin>>x;
            sum+=x;
        }
        cout<<(sum%n)*(n-(sum%n))<<endl;
    }
    return 0;
}