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