import math
t = int(input())
for _ in range(t):
    n = int(input())
    arr = list(map(int, input().split()))
    if (sum(arr)%n==0):
        print(0)
    else:
        s = sum(arr)
        if s == 2:
            print(4)
        else:
            print(s%n * math.ceil(math.log(s%n, 2)))