#include <bits/stdc++.h>

using namespace std;

void solve() {
  int n;
  cin >> n;
  long long s = 0;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    s += x;
  }
  cout << 1ll * (s % n) * (n - s % n);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }

  return 0;
}
