#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void solve() {
  int 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 << "\n";
  else {
    long long int x = s % n;
    cout << x * (n - x) << "\n";
  }
}
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);
  return 0;
}
