#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll total = 0;
    for (ll i = 0; i < n; i += 1) {
      ll input;
      cin >> input;
      total += input;
    }
    ll r = total % n;
    cout << r * (n - r) << "\n";
  }
  return 0;
}
