#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void solve() {
  int n;
  cin >> n;
  vector<int> traffic(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> traffic[i];
    sum += traffic[i];
  }
  int x = sum % n;
  cout << x * (n - x) << endl;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
