import sys
sys.stderr = sys.stdout


def solve(n, A):
    i = sum(A) % n
    j = n - i
    return i * j


def case():
    n = readint()
    A = readintl()
    m = solve(n, A)
    return str(m)


def main():
    t = readint()
    print('\n'.join(case() for _ in range(t)))

##########

def readint():
    return int(input())


def readinti():
   return map(int, input().split())


def readintt():
   return tuple(readinti())


def readintl():
   return list(readinti())


def readinttl(k):
    return [readintt() for _ in range(k)]


def readintll(k):
    return [readintl() for _ in range(k)]

def lstr(l):
    return ' '.join(map(str, l))

def llstr(ll):
    return '\n'.join(map(lstr, ll))


def log(*args, **kwargs):
    print(*args, **kwargs, file=sys.__stderr__)


if __name__ == '__main__':
    main()
