#include <bits/stdc++.h>
int min(int a, int b) {
  if (a <= b) return a;
  return b;
}
int max(int a, int b) {
  if (a >= b) return a;
  return b;
}
int main() {
  int t;
  scanf("%d", &t);
  int res[t];
  for (int i = 0; i < t; ++i) {
    int n;
    scanf("%d", &n);
    int ary[n];
    for (int j = 0; j < n; ++j) scanf("%d", &ary[j]);
    int sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += ary[j];
    }
    int remainder = sum % n;
    res[i] = remainder * (n - remainder);
  }
  for (int i = 0; i < t; ++i) {
    printf("%d\n", res[i]);
  }
}
