#include<bits/stdc++.h>
using namespace std;
using namespace chrono;
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define endl "\n"

void solve()
{
   ll n,s=0;
   cin>>n;
   vector<int> v(n);
   for(int i=0;i<n;i++)
   {
      cin>>v[i];
      s+=v[i];
   }

   if(s%n==0)
      cout<<0<<endl;
   else
   {
      ll x=s%n;
      cout<<x*(n-x)<<endl;
   }
}

signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);cout.tie(0);
   auto start = high_resolution_clock::now();
   int t=1;
   cin>>t;
   while(t--){
      solve();
   }
   auto end = high_resolution_clock::now();
   auto duration = duration_cast<microseconds>(end - start);
   //cout<<endl<< "Time Taken: " << duration . count() / 1000 << " ms" << endl;
   return 0;
}