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