import math
import sys


def scan():
    return list(map(int, sys.stdin.readline().strip().split()))


def solution():
    for _ in range(int(input())):
        n = int(input())
        a = scan()
        x = sum(a) % n
        p = sum(a) // n
        print(x*(n-x))

if __name__ == '__main__':
    solution()
