#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define N 1005

int main(){
    ios_base::sync_with_stdio(false);
    ll t;
    
    cin>>t;
    while(t--){
      ll n;
      cin>>n;
      vector<ll> v(n);
      ll sum=0;
      for(ll i=0;i<n;i++){
      cin>>v[i];
      sum+=v[i];
    }
    ll k=sum%n;
    cout<<k*(n-k)<<endl;
    }
}