from math import ceil
from sys import stdin, stdout

def main():
    input = stdin.readline
    print = stdout.write
    for _ in range(int(input())):
        N = int(input())
        Array = list(map(int, input().split()))
        Sum = sum(Array)
        print(str(Sum % N * (N - Sum % N)) + "\n")



main()