#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int t;
  cin >> t;
  while (t--) {
    int n, sum = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    int p = sum % n;
    if (p == 0)
      cout << "0" << endl;
    else
      cout << p * (n - p) << endl;
  }
  return 0;
}
