#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int len = n;
    vector<int> arr;
    int total_sum = 0;
    while (n--) {
      int temp;
      cin >> temp;
      total_sum += temp;
      arr.push_back(temp);
    }
    cout << (len - total_sum % len) * (total_sum % len) << endl;
  }
  return 0;
}
