#include <iostream>
#include <inttypes.h>

using namespace std;

int main() {

	int t;
	int n;
	uint64_t s;

	scanf("%d", &t);

	while (t--) {
		s = 0;

		scanf("%d", &n);

		for (int i = 0, temp = 0; i < n; i++) {
			scanf("%d", &temp);
			s += temp;
		}

		if (n == 1) {
			printf("0\n");
		} else {
			printf("%" PRIu64 "\n", (uint64_t)((s % n) * (n - (s % n)))); // (uint64_t)((s % n) * (n - (s % n)))
		}
	}

	return 0;
}