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