#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int a[N];
void KhanhNgok() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int x = sum % n;
  cout << x * (n - x) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    KhanhNgok();
  }
  return 0;
}
