#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int a[MAXN];
void sol() {
  int n, sum = 0;
  cin >> n;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int b = 0, k = 0;
  b = sum / n;
  k = sum - b * n;
  if (k == 0) {
    cout << 0 << endl;
  } else {
    cout << k * (n - k) << endl;
  }
}
int main() {
  int N;
  cin >> N;
  while (N--) {
    sol();
  }
  return 0;
}
