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