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