#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;

/*
  remember: precomputation should be done in main
*/
void solve(){
  int n; cin >> n;
  vector <int> nums(n);
  ll sum = 0;
  for(int i=0; i<n; i++){
    cin >> nums[i];
    sum += nums[i];
  }
  cout << (n-sum%n)*(sum%n) << '\n';
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int t; cin >> t;
  while(t--) solve();
  return 0;
}
