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