#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int c, b, s, q;
  while (n--) {
    cin >> c;
    int C = c;
    s = 0;
    while (C--) {
      int x;
      cin >> x;
      s += x;
    }
    q = s % c;
    cout << q * (c - q) << endl;
  }
  return 0;
}
