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