#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  int i, s = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  int d = s % n;
  int ans = d * (n - d);
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
