#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int suma = 0;
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      suma += a;
    }
    if (suma % n == 0) {
      cout << 0 << endl;
    } else {
      int res = (suma % n) * (n - suma % n);
      cout << res << endl;
    }
  }
}
