Polycarp has $n$ friends, the $i$-th of his friends has $a_i$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $a_i$ to be the same. To solve this, Polycarp performs the following set of actions exactly once:

Polycarp chooses $k$ ($0 \le k \le n$) arbitrary friends (let's say he chooses friends with indices $i_1, i_2, \ldots, i_k$);

Polycarp distributes their $a_{i_1} + a_{i_2} + \ldots + a_{i_k}$ candies among all $n$ friends. During distribution for each of $a_{i_1} + a_{i_2} + \ldots + a_{i_k}$ candies he chooses new owner. That can be any of $n$ friends. Note, that any candy can be given to the person, who has owned that candy before the distribution process.

Note that the number $k$ is not fixed in advance and can be arbitrary. Your task is to find the minimum value of $k$.

For example, if $n=4$ and $a=[4, 5, 2, 5]$, then Polycarp could make the following distribution of the candies:

Polycarp chooses $k=2$ friends with indices $i=[2, 4]$ and distributes $a_2 + a_4 = 10$ candies to make $a=[4, 4, 4, 4]$ (two candies go to person $3$).

Note that in this example Polycarp cannot choose $k=1$ friend so that he can redistribute candies so that in the end all $a_i$ are equal.

For the data $n$ and $a$, determine the minimum value $k$. With this value $k$, Polycarp should be able to select $k$ friends and redistribute their candies so that everyone will end up with the same number of candies.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^4$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case output:

the minimum value of $k$, such that Polycarp can choose exactly $k$ friends so that he can redistribute the candies in the desired way;

"-1" if no such value $k$ exists.


-----Examples-----

Input
5
4
4 5 2 5
2
0 4
5
10 8 5 1 4
1
10000
7
1 1 1 1 1 1 1
Output
2
1
-1
0
0


-----Note-----

None

Difficulty: EASY
Tags: Mathematics

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
t = int(input())

def solver(arr, n):
	s = sum(arr)
	count = 0
	if s % n != 0:
		return -1
	else:
		thresh = sum(arr) // n
		for i in range(n):
			if arr[i] > thresh:
				count += 1
	return count
res = []
for i in range(t):
	n = int(input())
	arr = [int(item) for item in input().split()]
	res.append(solver(arr, n))
for r in res:
	print(r)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	t = sum(l)
	if t % n != 0:
		print(-1)
	else:
		k = t // n
		c = 0
		for i in l:
			if i > k:
				c += 1
		print(c)


import sys
input = sys.stdin.readline
output = sys.stdout.write

def main():
	tests = int(input().rstrip())
	for i in range(tests):
		length_ = int(input().rstrip())
		nums_ = list(map(int, input().rstrip().split()))
		summ = sum(nums_)
		if summ % length_ == 0:
			res = int(summ / length_)
			ans = 0
			for _ in nums_:
				ans += _ > res
			output(str(ans))
		else:
			output('-1')
		output('\n')
main()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n != 0:
		print(-1)
		return
	v = s // n
	k = 0
	for i in a:
		k += i > v
	print(k)
for i in range(int(input())):
	solve()


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	sr = sum(s) // n
	if sr * n != sum(s):
		print(-1)
	else:
		print(len(list(filter(lambda x: x > sr, s))))


t = int(input())
while t > 0:
	n = int(input())
	a = [int(i) for i in input().split()]
	if sum(a) % n != 0:
		print(-1)
	else:
		c = 0
		req = sum(a) // n
		for i in a:
			if i > req:
				c += 1
		print(c)
	t -= 1


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = sum(a)
	if t % n:
		print(-1)
	else:
		t //= n
		ans = 0
		for i in a:
			if i > t:
				ans += 1
		print(ans)


from sys import *
ws = lambda : map(int, stdin.readline().strip().split())
li = lambda : list(map(int, stdin.readline().strip().split()))
mod = 1000000007

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def prod(l):
	ans = 1
	for i in range(len(l)):
		ans = ans * l[i]
	return ans

def sortindex(l, a):
	c = []
	if a == -1:
		rev = True
	else:
		rev = False
	for i in range(len(l)):
		c.append([l[i], i])
	x = sorted(c, reverse=rev)
	print(x)
	c = []
	for i in range(len(l)):
		c.append(x[i][1])
	return c
for _ in range(int(input())):
	n = int(input())
	l = li()
	maxi = sum(l)
	if maxi % n != 0:
		print(-1)
	else:
		maxi = maxi // n
		ans = 0
		for x in l:
			if x > maxi:
				ans += 1
		print(ans)


from sys import stdin, stdout, setrecursionlimit as srl
from threading import stack_size
from collections import deque, defaultdict as dd
from math import gcd, ceil
input = stdin.readline
flush = stdout.flush

def ub(arr, lo, hi, val):
	while lo < hi:
		mid = (lo + hi) // 2
		if arr[mid] > val:
			hi = mid - 1
		elif arr[mid] <= val:
			lo = mid + 1
	if lo == len(arr) - 1 and arr[-1] <= val:
		lo = len(arr)
	return lo

def lb(arr, lo, hi, val):
	while lo < hi:
		mid = (lo + hi) // 2
		if arr[mid] < val:
			lo = mid + 1
		elif arr[mid] >= val:
			hi = mid - 1
	if lo == len(arr) - 1 and arr[-1] < val:
		lo = len(arr)
	return lo
tc = 1
tc = int(input())
for _ in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	x = sum(a)
	if x % n != 0:
		print('-1')
		continue
	x = x // n
	a.sort(reverse=True)
	ans = 0
	for i in a:
		if i > x:
			ans += 1
		else:
			break
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if sum(l) % n:
		print('-1')
	else:
		k = sum(l) / n
		ans = 0
		for i in l:
			if i > k:
				ans += 1
		print(ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n != 0:
		print(-1)
	else:
		(d, ans) = (s // n, 0)
		for i in a:
			if i > d:
				ans += 1
		print(ans)
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n:
		ans = -1
	else:
		x = s // n
		ans = 0
		for i in a:
			if i > x:
				ans += 1
	print(ans)


import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10 ** 5)

def rarray():
	return [int(i) for i in input().split()]
t = 1
t = int(input())
for ii in range(t):
	n = int(input())
	a = rarray()
	a.sort()
	s = sum(a)
	if s % n != 0:
		print(-1)
		continue
	k = s // n
	print(n - bisect_right(a, k))


t = int(input())
for z in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ss = sum(arr)
	if len(set(arr)) == 1:
		print(0)
	elif (ss / n).is_integer():
		k = ss // n
		count = 0
		for i in range(n):
			if arr[i] > k:
				count = count + 1
		print(count)
	else:
		print(-1)


from collections import Counter
import string
import math
import bisect
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = vary(1)
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	if sum(num) % n != 0:
		print(-1)
	else:
		ans = sum(num) // n
		value = 0
		for i in range(n):
			if num[i] > ans:
				value += 1
		print(value)


for i in range(int(input())):
	n = int(input())
	arr = [int(arr) for arr in input().split()]
	arr.sort()
	if n == 1 or arr[0] == arr[-1]:
		print(0)
	elif sum(arr) % n != 0:
		print(-1)
	else:
		k = 0
		goal = sum(arr) // n
		a = [i for i in arr if i > goal]
		print(len(a))


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % n != 0:
		print(-1)
		continue
	cnt = n
	for i in range(n):
		if arr[i] * n <= s:
			cnt -= 1
	print(cnt)


def GetList():
	return list(map(int, input().split()))

def solve():
	t = int(input())
	for num in range(t):
		n = int(input())
		arr = GetList()
		arr = sorted(arr)
		if sum(arr) % n != 0:
			print('-1')
		else:
			ans = sum(arr) // n
			i = 0
			for candies in arr:
				if candies > ans:
					break
				i += 1
			print(n - i)
solve()


t = int(input())
for l in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	s = sum(a)
	ans = 0
	if s % n != 0:
		print(-1)
	else:
		for i in a:
			if i > s / n:
				ans += 1
		print(ans)


k = []
for i in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	x = sum(a)
	l = x // n
	if x % n != 0:
		k.append(-1)
	else:
		d = [t for t in a if t > l]
		k.append(len(d))
for t in k:
	print(t)


for i in range(int(input())):
	c = int(input())
	ar = list(map(int, input().split()))
	avg = sum(ar) / c
	if avg == int(avg):
		ans = 0
		for e in ar:
			if e > avg:
				ans += 1
	else:
		ans = -1
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split()))
	a = sum(l) / n
	l.sort()
	c = 0
	if a.is_integer() == False:
		print(-1)
	else:
		for i in range(len(l)):
			if l[i] > a:
				c += 1
		print(c)


import os
import sys
from io import BytesIO, IOBase
from functools import lru_cache, reduce
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from bisect import bisect, bisect_left, bisect_right
import math
import threading
import time
from copy import deepcopy

def I():
	return input()

def get_int():
	return int(input())

def get_list():
	return list(map(int, input().split()))

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

def get_list_str(li, s=' '):
	print(s.join(map(str, li)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve():
	n = get_int()
	ls = get_list()
	ans = -1
	if sum(ls) % n == 0:
		val = sum(ls) // n
		cnt = 0
		for value in ls:
			if value > val:
				cnt += 1
		ans = cnt
	print(ans)

def main():
	testcases = True
	if testcases:
		t = get_int()
		for _ in range(t):
			solve()
	else:
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	candies = list(map(int, input().split()))
	sum = 0
	result = 0
	for candyValue in candies:
		sum += candyValue
	if sum % n != 0:
		result = -1
	else:
		count = 0
		for i in range(n):
			if candies[i] > sum // n:
				count += 1
		result = count
	print(result)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	sumall = 0
	for i in range(n):
		sumall += a[i]
	if sumall % n == 0:
		flag = True
	else:
		flag = False
	val = sumall / n
	for i in range(n):
		if a[i] > val:
			count += 1
	if flag == False:
		print(-1)
	else:
		print(count)
	t -= 1


res = ''
for _ in range(int(input())):
	n = int(input())
	arr = tuple(map(int, input().split()))
	avg = sum(arr) / n
	if avg % 1 != 0:
		res += '-1\n'
	else:
		ans = 0
		for num_candies in arr:
			if num_candies > avg:
				ans += 1
		res += '%d\n' % ans
print(res)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	if n == 1 or len(s) == 1:
		print(0)
	elif sum(l) % n != 0:
		print(-1)
	else:
		a = sum(l) // n
		c = 0
		for i in l:
			if i > a:
				c += 1
		print(c)


for s in [*open(0)][2::2]:
	s = (*map(int, s.split()),)
	(x, n) = (sum(s), len(s))
	if x % n != 0:
		print(-1)
	else:
		print(sum((i > x / n for i in s)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	suma = sum(a)
	if suma % n != 0:
		print(-1)
	else:
		obj = suma // n
		res = 0
		for i in a:
			if i > obj:
				res += 1
		print(res)


def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	if sum(a) % n != 0:
		print(-1)
		return
	else:
		rat = sum(a) // n
		b = [elem - rat for elem in a]
		res = sum([1 if elem > 0 else 0 for elem in b])
		print(res)
		return
for t in range(int(input())):
	solve()


t = int(input())
lan = []
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	avg = sum(x) / len(x)
	ctr = 0
	flag = False
	if avg % 1 != 0.0:
		lan.append(-1)
		flag = True
	else:
		for indx in range(len(x)):
			if x[indx] > avg:
				ctr += 1
			else:
				continue
	if flag == False:
		lan.append(ctr)
print(*lan, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		total = sum(a)
		if total % n == 0:
			avg = total // n
			count = 0
			for i in range(n):
				if avg < a[i]:
					count += 1
			print(count)
		else:
			print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sum_a = sum(a)
	if sum_a % n != 0:
		print(-1)
	else:
		average = sum_a // n
		ans = 0
		for j in a:
			if average < j:
				ans += 1
		print(ans)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	a = list(map(int, input().split()))
	m = sum(a) / n
	if int(m) - m == 0:
		print(len([x for x in a if x > m]))
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = sum(a) / n
	k = 0
	if m != int(m):
		print(-1)
		continue
	else:
		for j in range(n):
			if a[j] > m:
				k = k + 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	gift = list(map(int, input().split()))
	avrg = sum(gift) / n
	count = 0
	if avrg.is_integer():
		for x in gift:
			if x > avrg:
				count += 1
		print(count)
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	k = 0
	extraSum = 0
	for i in l:
		c += i
	if c % n != 0:
		print(-1)
	else:
		c = c // n
		for i in range(n):
			if l[i] > c:
				extraSum += l[i] - c
				l[i] = c
				k += 1
		for i in range(n):
			if l[i] < c and extraSum >= c - l[i]:
				a = c - l[i]
				l[i] = l[i] + a
				extraSum -= a
		print(k)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n != 0:
		print(-1)
	else:
		print(sum([1 for i in a if i > s // n]))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n != 0:
		print(-1)
		continue
	sn = s // n
	t = 0
	for j in range(n):
		t += max(0, a[j] - sn)
	k = 0
	st = 0
	j = n - 1
	a.sort()
	while st < t:
		st += a[j] - sn
		j -= 1
		k += 1
	print(k)


R = lambda : list(map(int, input().split()))
for _ in ' ' * int(input()):
	n = R()[0]
	a = R()
	s = sum(a)
	c = 0
	if s % n:
		print(-1)
	else:
		av = s // n
		for i in a:
			if i > av:
				c += 1
		print(c)


t = int(input())
cases = [(int(input()), list(map(int, input().split()))) for _ in range(t)]
for case in cases:
	(n, arr) = (case[0], case[1])
	avg = sum(arr) / n
	if avg % 1 != 0:
		print('-1')
	elif n == 1 or n == arr.count(arr[0]):
		print('0')
	else:
		print(len([x for x in arr if x > avg]))


t = int(input())
for jj in range(t):
	nn = int(input())
	candle = list(map(int, input().split()))
	if sum(candle) % nn != 0:
		print(-1)
		continue
	else:
		ideal = sum(candle) // nn
		count = sum((i > ideal for i in candle))
		print(count)


def fun(l, n):
	s = sum(l)
	if s % n != 0:
		return -1
	a = s // n
	count = 0
	for i in l:
		if i > a:
			count += 1
	return count
n = int(input())
p = []
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	p.append(fun(a, m))
for i in p:
	print(i)


from sys import stdin
from sys import stdout
from math import *
import sys
input = stdin.readline
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	if sum(ar) % n != 0:
		print(-1)
	else:
		ar.sort()
		x = sum(ar) // n
		ans = 0
		ar = ar[::-1]
		for i in range(n):
			if ar[i] > x:
				ans = i + 1
		print(ans)


num = int(input())
ans = ''
for j in range(num):
	n = int(input())
	(cot, change) = (0, 0)
	ls = list(map(int, input().split()))
	s = sum(ls)
	if s % n == 0:
		ans += f'{len([i for i in ls if i > s // len(ls)])}\n'
	else:
		ans += f'{-1}\n'
print(ans)


import sys
t = int(sys.stdin.readline())
while t != 0:
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	if sum(a) % n != 0:
		print(-1)
	elif len(a) == 1:
		print(0)
	else:
		avg = sum(a) // n
		x = [i for i in a if i > avg]
		print(len(x))
	t -= 1


def main() -> None:
	for t in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		s = sum(a)
		if s % n != 0:
			print(-1)
		else:
			b = s // n
			print(sum((1 for c in a if c > b)))
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if sum(arr) % n != 0:
		print('-1')
	else:
		cnt = 0
		f = sum(arr) // n
		for i in arr:
			if i > f:
				cnt += 1
		print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	summ = sum(a)
	ans = 0
	less = 0
	each = summ // n
	addd = 0
	for k in range(0, n):
		if a[k] > each:
			ans += 1
			addd += a[k] - each
		else:
			less += each - a[k]
			continue
	if addd == less:
		print(ans)
	else:
		print(-1)


def main():
	t = int(input())
	ans = []
	for _ in range(t):
		n = int(input())
		candies = list(map(int, input().split()))
		tot = sum(candies)
		temp = 0
		if tot % n == 0:
			for i in candies:
				if i > tot / n:
					temp += 1
			ans.append(temp)
		else:
			ans.append(-1)
	for i in ans:
		print(i)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	d = s / n
	k = 0
	if d != int(d):
		print(-1)
	else:
		for i in a:
			if i > d:
				k += 1
		print(k)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	pre = sum(l) / n
	ex = sum(l) // n
	if pre != ex:
		print('-1')
	else:
		res = 0
		for i in l:
			if i > ex:
				res += 1
		print(res)


def checker(arr, l):
	sum = 0
	for i in arr:
		sum += i
	if sum % l != 0:
		print(-1)
	else:
		i = 0
		a = sum / l
		for j in arr:
			if j > a:
				i += 1
		print(i)
t = int(input())
for i in range(t):
	l = int(input())
	pow = list(map(int, input().split()))
	checker(pow, l)


ans = []
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	accu = sum(arr)
	if accu % n:
		ans.append(-1)
		continue
	avg = accu // n
	count = 0
	for i in arr:
		count += i > avg
	ans.append(count)
for i in ans:
	print(i)


t = int(input())
while t != 0:
	n = int(input())
	l = list(map(int, input().split()))
	p = sum(l) // n
	c = 0
	if sum(l) % n != 0:
		print(-1)
	else:
		for i in l:
			if i > p:
				c = c + 1
		print(c)
	t = t - 1


t = int(input())
out = []
for x in range(t):
	n = int(input())
	a = input()
	b = a.split()
	b = list(map(int, b))
	avg = sum(b) / len(b)
	if avg % 1 != 0:
		out.append(-1)
	else:
		k = 0
		b = sorted(b, reverse=True)
		for y in range(len(b)):
			if b[y] > avg:
				k += 1
		out.append(k)
for x in range(t):
	print(out[x])


ans = []
for _ in range(int(input())):
	n = int(input())
	candy = [*map(int, input().split())]
	total = sum(candy)
	if n == 1:
		ans += [0]
	elif total % n:
		ans += [-1]
	else:
		k = [x for x in candy if x > total // n]
		ans += [len(k)]
print('\n'.join(map(str, ans)))


import sys

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

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

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		arr = get_list()
		summ = sum(arr)
		if summ % n != 0:
			get_print_int(-1)
		else:
			num = summ // n
			ans = 0
			for i in range(n):
				if arr[i] > num:
					ans += 1
			get_print_int(ans)
solve()


T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	m = sum(A) / len(A)
	if m != int(m):
		print('-1')
		continue
	count = 0
	for a in A:
		if a > m:
			count += 1
	print(count)


import math
from collections import Counter, defaultdict
import sys
mod = 10 ** 9 + 7
input = sys.stdin.readline
readInt = lambda : int(input().strip())
readfloat = lambda : float(input().strip())
readStr = lambda : input().strip()
intList = lambda : list(map(int, input().strip().split()))
intMap = lambda : map(int, input().strip().split())
floatList = lambda : list(map(float, input().strip().split()))
floatMap = lambda : map(float, input().strip().split())
strList = lambda : list(input().strip().split())

def print(*args, end='\n', sep=' '):
	for i in args:
		sys.stdout.write(str(i))
		sys.stdout.write(sep)
	sys.stdout.write(end)

def solve(arr):
	avg = sum(arr) / n
	if avg != int(avg):
		return -1
	res = 0
	for i in arr:
		res += max(0, avg - i)
	arr.sort(reverse=True)
	k = 0
	req_sum = 0
	for i in arr:
		if req_sum == res:
			return k
		k += 1
		req_sum += i - avg
for _ in range(readInt()):
	n = readInt()
	arr = intList()
	print(solve(arr))


a = int(input())
for x in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = sum(c) // b
	o = 0
	if sum(c) % b != 0:
		print(-1)
		continue
	else:
		for x in c:
			if x > d:
				o += 1
	print(o)


t = int(input())
for _ in range(0, t):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	if sum(arr) % n != 0:
		print(-1)
	else:
		cnt = 0
		av = sum(arr) / n
		for el in arr:
			if el > av:
				cnt += 1
		print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	summ = 0
	am = 0
	k = 0
	for i in range(n):
		summ += a[i]
	if summ % n != 0:
		print(-1)
	else:
		am = summ / n
		for i in range(n):
			if a[i] > am:
				k += 1
		print(k)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = sum(l) // n
	c = -1
	if sum(l) % n == 0:
		c = 0
		for val in l:
			if val > d:
				c += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	summ = sum(l)
	if n == 1:
		print(0)
		continue
	if summ // n != summ / n:
		print(-1)
		continue
	cnt = 0
	q = summ // n
	for i in l:
		if i > q:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	siz = int(input())
	lis = list(map(int, input().split()))
	lsum = sum(lis)
	if lsum % siz != 0:
		print(-1)
	else:
		res = 0
		k = lsum // siz
		for i in lis:
			if i > k:
				res += 1
		print(res)


def fun(n, arr):
	total = sum(arr)
	if total % n != 0:
		return -1
	ans = 0
	val = total // n
	for i in range(0, n):
		if arr[i] - val > 0:
			ans = ans + 1
	return ans
for i in range(0, int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = fun(n, arr)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print('0')
	elif l.count(l[0]) == n:
		print('0')
	elif sum(l) % n == 0:
		r = sum(l) // n
		c = 0
		for i in l:
			if i > r:
				c += 1
		print(c)
	else:
		print('-1')


def solve(n, a):
	if sum(a) % n != 0:
		return -1
	x = sum(a) // n
	c = 0
	c = sum((1 for i in a if i > x))
	return c
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


t = int(input())
for i in range(t):
	n = int(input())
	result = 0
	friends = list(map(int, input().strip().split()))
	if sum(friends) % n == 0:
		avg = sum(friends) / n
		for friend in friends:
			if friend > avg:
				result += 1
		print(result)
	else:
		print('-1')


from collections import Counter
tcs = int(input())
for tc in range(tcs):
	n = int(input())
	A = [int(n) for n in input().split()]
	total = sum(A)
	if total % n != 0:
		print(-1)
		continue
	above = 0
	avg = total // n
	for c in A:
		if c > avg:
			above += 1
	print(above)


t = int(input())
while t > 0:
	n = int(input())
	lst = [int(x) for x in input().split()]
	candynum = sum(lst) / n
	count = 0
	for i in lst:
		if i > candynum:
			count += 1
	if sum(lst) % n != 0:
		print('-1')
	else:
		print(count)
	t = t - 1


import sys
sys.setrecursionlimit(10 ** 6)
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().strip()
nsa = lambda : list(map(str, stdin.readline().split()))
ntp = lambda : tuple(map(int, stdin.readline().split()))
mod = 10 ** 9 + 7
inf = 10 ** 18
t = ni()
for _ in range(t):
	n = ni()
	A = na()
	sm = sum(A)
	if sm % n:
		print(-1)
		continue
	ave = sm // n
	ans = 0
	for a in A:
		if a > ave:
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	som = sum(l)
	if som % n != 0:
		print(-1)
		continue
	ans = 0
	val = som // n
	for i in l:
		if i > val:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if sum(lis) % n:
		print(-1)
		continue
	ans = 0
	avg = sum(lis) // n
	print(sum([1 for x in lis if x > avg]))


import sys
import math
inputlines = sys.stdin.readlines()

def find_all_elements_greater_than_x(elements, x):
	number_of_elements_greater_than_x = 0
	for i in elements:
		if i > x:
			number_of_elements_greater_than_x += 1
	return number_of_elements_greater_than_x
number_of_testcases = int(inputlines[0])
for i in range(number_of_testcases):
	number_of_elements = int(inputlines[2 * i + 1])
	elements = list(map(int, inputlines[2 * i + 2].split(' ')))
	avg = sum(elements) / number_of_elements
	if math.ceil(avg) != math.floor(avg):
		print(-1)
	else:
		number_of_elements_greater_than_avg = find_all_elements_greater_than_x(elements, int(avg))
		print(number_of_elements_greater_than_avg)


import sys
tasks = sys.stdin.read().splitlines()[1:]
test_cases = zip(tasks[::2], tasks[1::2])
k = []
for test in test_cases:
	n = int(test[0])
	a = list(map(int, test[1].split(' ')))
	if sum(a) % n != 0:
		print(-1)
		continue
	if n == 1 or a.count(a[0]) == n:
		print(0)
		continue
	eq = sum(a) / n
	k = [i for i in a if i > eq]
	print(len(k))


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	n = len(a)
	t = sum(a)
	print((sum((x * n > t for x in a)), -1)[t % n > 0])


def solve():
	cases = int(input())
	while cases > 0:
		cases -= 1
		n = int(input())
		a = [int(num) for num in input().split()]
		sum_value = sum(a)
		if sum_value % n == 0:
			ans = 0
			avg = sum_value // n
			for ai in a:
				if ai > avg:
					ans += 1
			print(ans)
		else:
			print(-1)
solve()


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd, log
import bisect
import sys
import copy

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	arr = get_array()
	arr.sort()
	if sum(arr) % n == 0:
		print(n - bisect.bisect_right(arr, sum(arr) // n))
	else:
		print(-1)


ans = []
for _ in range(int(input())):
	n = int(input())
	candy = [*map(int, input().split())]
	total = sum(candy)
	if n == 1:
		ans += [0]
	elif total % n:
		ans += [-1]
	else:
		candy.sort(reverse=True)
		average = total // n
		k = 0
		for x in candy:
			if x > average:
				k += 1
			else:
				break
		ans += [k]
print('\n'.join(map(str, ans)))


data = []
for _ in range(int(input())):
	input()
	data.append(list(map(int, input().split())))
for arr in data:
	s = sum(arr)
	n = len(arr)
	if s % n:
		print(-1)
	else:
		val = s // n
		k = 0
		for i in arr:
			if i < val:
				k += val - i
		if k == 0:
			print(0)
		else:
			arr.sort(reverse=True)
			L = 0
			R = len(arr) - 1
			while L <= R:
				mid = (L + R) // 2
				if arr[mid] >= val:
					L = mid + 1
				else:
					R = mid - 1
			index = R
			for i in range(1, len(arr)):
				arr[i] += arr[i - 1]
			L = 0
			R = index
			while L <= R:
				mid = (L + R) // 2
				if arr[mid] - val * (mid + 1) >= k:
					R = mid - 1
				else:
					L = mid + 1
			print(R + 2)


t = int(input())
for _ in range(t):
	size = int(input())
	arr = list(map(int, input().split()))
	val1 = sum(arr)
	if val1 % size == 0:
		k = val1 // size
		count = 0
		for i in range(size):
			if arr[i] > k:
				count = count + 1
		print(count)
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort(reverse=True)
	SUM = sum(arr)
	if SUM % n != 0:
		print(-1)
	else:
		each = SUM // n
		curr = 0
		ans = -1
		for i in range(n):
			if arr[i] <= each:
				ans = i
				break
		print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = sum(l)
	cc = 0
	if x % n == 0:
		t = x // n
		for i in l:
			if i > t:
				cc += 1
		print(cc)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	su = sum(s)
	if su % n != 0:
		print(-1)
	else:
		av = su // n
		s.sort(reverse=True)
		q = 0
		while s[q] > av:
			q += 1
		print(q)


for _ in range(int(input())):
	n = int(input())
	lst = [int(x) for x in input().split()]
	if sum(lst) % n != 0:
		ans = -1
	elif len(set(lst)) == 1:
		ans = 0
	else:
		s = sum(lst) // n
		minus = [x - n for x in lst if x > s]
		ans = len(minus)
	print(ans)


import math
import sys
import collections
import bisect
import time
import random
from itertools import permutations
import string

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	n = int(input())
	arr = get_list()
	if sum(arr) % n != 0:
		print(-1)
		continue
	arr.sort(reverse=True)
	avg = sum(arr) // n
	ans = 0
	for i in arr:
		if i > avg:
			ans += 1
	print(ans)


test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	arr = list(map(int, input().split()))
	if sum(arr) % n != 0:
		print(-1)
		continue
	var = int(sum(arr) / n)
	count = 0
	for i in arr:
		if i > var:
			count += 1
	print(count)


from bisect import bisect_right
for _ in range(int(input())):
	(n, friends) = (int(input()), list(map(int, input().split(' '))))
	friends_mid = sum(friends)
	if friends_mid % n != 0:
		print(-1)
	else:
		friends.sort()
		print(len(friends[bisect_right(friends, friends_mid // n):]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sa = sum(a)
	if sa % n != 0:
		print(-1)
	else:
		ans = 0
		eq = sa / n
		for i in a:
			if i > eq:
				ans += 1
		print(ans)


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	sumd = sum(arr)
	c = 0
	if sumd % len(arr):
		c = -1
	else:
		val = sumd / len(arr)
		for i in range(len(arr)):
			if val < arr[i]:
				c += 1
	print(c)
	t -= 1


def func():
	n = int(input())
	lst = list(map(int, input().split()))
	lstSum = sum(lst)
	cnt = 0
	if lstSum % n == 0:
		avg = lstSum // n
		for i in lst:
			if i > avg:
				cnt += 1
		print(cnt)
	else:
		print(-1)

def main():
	for i in range(int(input())):
		func()
main()


import math
from functools import reduce
from math import comb
from collections import defaultdict
from sys import stdout
NO = 'NO'
YES = 'YES'
MOD = 1000000007
ALPH = 'abcdefghijklmnopqrstuvwxyz'

def input_int():
	return int(input())

def input_list():
	return input().split(' ')

def input_list_int():
	return list(map(int, input_list()))

def list_int_to_str(a, sep=' '):
	return sep.join((str(x) for x in a))
global_ans = []

def pr(a):
	global_ans.append(a)

def solve():
	n = input_int()
	a = input_list_int()
	s = sum(a)
	if s % n != 0:
		pr(-1)
	else:
		p = s // n
		k = 0
		for i in a:
			if i > p:
				k += 1
		pr(k)
query_count = 1
query_count = input_int()
while query_count:
	query_count -= 1
	solve()
for global_ans_line in global_ans:
	print(global_ans_line)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
from math import *
from bisect import *
from heapq import *
from functools import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import *
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)
MAX = 10 ** 5

def solve():
	n = takeint()
	arr = takeiarr()
	if n == 1:
		print(0)
	if arr.count(arr[0]) == n and n != 1:
		print(0)
	if arr.count(arr[0]) != n:
		total = sum(arr)
		if total % n != 0:
			print(-1)
		else:
			each = total // n
			count = 0
			for i in range(n):
				if arr[i] > each:
					count += 1
				else:
					pass
			print(count)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = takeint()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def takeint():
	return int(sys.stdin.readline().rstrip('\r\n'))

def takestr():
	return sys.stdin.readline().rstrip('\r\n')

def takeiarr():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesarr():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivar():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvar():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def swap(a, b):
	(a, b) = (b, a)
	return (a, b)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n):
	dp = [1] * (n + 1)
	for i in range(1, n + 1):
		dp[i] = dp[i - 1] * i
	return dp[n]

def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a

def isprime(n):
	if n > 2 and (not n % 2) or n == 1:
		return False
	for i in range(3, int(n ** 0.5 + 1), 2):
		if not n % i:
			return False
	return True

def binexp(a, b):
	if b == 0:
		return 1
	ans = binexp(a, b // 2)
	if b % 2:
		return ans * ans * a
	else:
		return ans * ans

def most_frequent(nums):
	return max(set(nums), key=nums.count)

def binary_search(nums, target):
	(low, high) = (0, len(nums) - 1)
	while low <= high:
		mid = (low + high) // 2
		if nums[mid] == target:
			return mid + 1
		if nums[mid] > target:
			high = mid - 1
		else:
			low = mid + 1
	return -1

def lcm(numbers):
	return reduce(lambda x, y: int(x * y / gcd(x, y)), numbers)

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import sys

def solve(a, n):
	total_sum = sum(a)
	if total_sum % n != 0:
		return -1
	else:
		avg = total_sum // n
		k = 0
		for i in range(n):
			if a[i] > avg:
				k += 1
		return k
i = sys.stdin.readline
for _ in range(int(i())):
	n = int(i())
	a = list(map(int, i().split()))
	result = solve(a, n)
	print(result)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	avg = sum(l) // n
	print(sum((i > avg for i in l)) if sum(l) % n == 0 else -1)


def solve():
	s = sum(ar)
	if s % n != 0:
		print(-1)
	else:
		avr = s // n
		re = 0
		for v in ar:
			if v > avr:
				re += 1
		print(re)
t = int(input())
for i in range(t):
	n = int(input())
	ar = [int(i) for i in input().split()]
	solve()


import math
t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	total = sum(a)
	if total % n != 0:
		print(-1)
	else:
		l = total / n
		for j in range(n):
			if a[j] <= l:
				break
			else:
				ans += 1
		print(ans)


def solve(N, A):
	sumA = sum(A)
	if sumA % N != 0:
		return -1
	avg = sumA // N
	cnt = 0
	for v in A:
		if v > avg:
			cnt += 1
	return cnt
T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	print(solve(N, A))


from collections import Counter as count
from bisect import bisect
import sys
from itertools import groupby
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	n = int(input())
	z = list(map(int, input().split()))
	isum = sum(z) / n
	left = 0
	right = 0
	k = 0
	for i in range(n):
		if z[i] > isum:
			left += z[i] - isum
			z[i] = isum
			k += 1
		else:
			right += isum - z[i]
	if left == right and int(isum) == isum:
		print(k)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
results = []
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	total = sum(arr)
	if total % n != 0:
		results.append(-1)
		continue
	if len(arr) == 1:
		results.append(0)
		continue
	standard = total / n
	num = 0
	for i in arr:
		if standard < i:
			num += 1
	results.append(num)
for i in results:
	print(i)


t = int(input())
while t > 0:
	count = 0
	n = int(input())
	arr = list(map(int, input().rstrip().split()))[:n]
	if sum(arr) % n != 0:
		print(-1)
	elif len(arr) == 1 or len(set(arr)) == 1:
		print(0)
	else:
		k = sum(arr) // n
		for x in arr:
			if x > k:
				count = count + 1
		print(count)
		arr.clear()
	t = t - 1


t = int(input())
arr = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = a[:n]
	k = 0
	s = sum(a) / len(a)
	if s % 1 != 0:
		arr.append(-1)
		continue
	for j in a:
		if j > s:
			k += 1
	arr.append(k)
for i in arr:
	print(i)


cases = int(input())
for _ in range(cases):
	n = int(input())
	candies = [int(ai) for ai in input().split()]
	total = sum(candies)
	if total % n != 0:
		print(-1)
		continue
	candies_per_person = total // n
	k = 0
	for ai in candies:
		if ai > candies_per_person:
			k += 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if sum(l) % n != 0:
		print(-1)
		continue
	s = sum(l) / n
	count = 0
	for e in l:
		if e > s:
			count += 1
	print(count)


import sys, os, io
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = sum(a)
	if s % n:
		print(-1)
		continue
	x = s // n
	big = 0
	for i in a:
		if i > x:
			big += 1
	print(big)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	s = 0
	for i in range(n):
		s = s + li[i]
	v = -1
	if s % n == 0:
		for i in range(n):
			if li[i] > s // n:
				v = i
				break
		if v == -1:
			print('0')
		else:
			print(n - v)
	else:
		print('-1')


def solve(n, a):
	total = sum(a)
	if total % n != 0:
		return -1
	avg = total // n
	return len([x for x in a if x > avg])
T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	result = solve(n, a)
	print(result)


from math import *

def minNumber(a):
	if sum(a) % len(a) != 0:
		return -1
	else:
		t = sum(a) // len(a)
		res = 0
		for i in a:
			if i > t:
				res += 1
		return res
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(minNumber(a))


import bisect
from collections import Counter

def main(a):
	s = sum(a)
	n = len(a)
	if s % n != 0:
		return -1
	m = s // n
	ct = sum((1 if x > m else 0 for x in a))
	return ct
t = int(input())
outputs = []
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	output = main(arr)
	outputs.append(output)
for o in outputs:
	print(o)


for s in [*open(0)][2::2]:
	l = map(int, s.split())
	lst = (*l,)
	if sum(lst) % len(lst):
		print('-1')
		continue
	s = sum(lst) // len(lst)
	total_pick = 0
	for n in lst:
		if n > s:
			total_pick += 1
	print(total_pick)


t = int(input())
b = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	average = sum(a) // n
	counter = 0
	if sum(a) % n == 0:
		for j in a:
			if j > average:
				counter += 1
		b.append(counter)
	else:
		b.append(-1)
for k in range(t):
	print(b[k])


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	total = sum(a)
	count = 0
	if a.count(a[0]) == n:
		print(0)
	elif total % n == 0:
		for x in a:
			if x > total / n:
				count += 1
		print(count)
	else:
		print(-1)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [int(x) for x in input().split()]
		total = sum(A)
		if total % N != 0:
			print(-1)
			continue
		ave = total // N
		ans = 0
		for a in A:
			if a > ave:
				ans += 1
		print(ans)
main()


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	sa = sum(a)
	if sa % n != 0:
		print(-1)
	else:
		dv = sa // n
		ans = 0
		for i in a:
			if i > dv:
				ans += 1
		print(ans)


t = eval(input())
for qwe in range(t):
	n = eval(input())
	a = input().split(' ')
	a = [eval(x) for x in a]
	s = sum(a)
	p = s / len(a)
	q = s // len(a)
	if p == q:
		c = 0
		for i in a:
			if i > p:
				c += 1
		print(c)
	else:
		print('-1')


import sys

def get_single_int():
	return int(sys.stdin.readline().strip())

def get_string():
	return sys.stdin.readline().strip()

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
for i in range(get_single_int()):
	n = get_single_int()
	ar = get_list()
	summ = sum(ar)
	if summ % n != 0:
		print(-1)
		continue
	ave = summ // n
	ans = 0
	for j in ar:
		if j > ave:
			ans += 1
	print(ans)


n = int(input())
for _ in range(n):
	input()
	arr = list(map(int, input().strip().split(' ')))
	sum_candies = sum(arr)
	size = len(arr)
	if sum_candies // size < sum_candies / size:
		print(-1)
	else:
		eq_num = sum_candies // size
		ans = 0
		for num in arr:
			if num > eq_num:
				ans += 1
		print(ans)


import sys
getline = sys.stdin.readline

def read_int():
	return int(getline())

def read_ints():
	return list(map(int, getline().split()))
for _ in range(read_int()):
	n = read_int()
	a = read_ints()
	s = sum(a)
	avg = s / n
	if avg - int(avg):
		print(-1)
		continue
	a.sort()
	k = 0
	for ele in a:
		if ele > avg:
			k += 1
	print(k)


for g in [*open(0)][2::2]:
	a = list(map(int, g.split()))
	s = sum(a)
	n = len(a)
	if s % n != 0:
		print(-1)
	else:
		d = s // n
		f = list(filter(lambda v: v > d, a))
		print(len(f))


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	l = li()
	s = sum(l)
	if s % n:
		pr(-1)
		return
	ans = 0
	for i in l:
		ans += i > s // n
	pr(ans)
for _ in range(inp()):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = sum(a)
	if s % n == 0:
		ret = 0
		m = s // n
		for x in a:
			if x > m:
				ret += 1
		print(ret)
	else:
		print('-1')


try:
	t = int(input())
	while t:
		n = int(input())
		arr = list(map(int, input().strip().split()))
		s = sum(arr)
		if s % n == 0:
			each = s // n
			ch = 0
			for i in range(0, n):
				if arr[i] > each:
					ch = ch + 1
			print(ch)
		else:
			print(-1)
		t = t - 1
except:
	pass


import sys
MOD = 1000000007
inp = sys.stdin.readline

def ii():
	return int(inp())

def iis():
	return [int(i) for i in inp().split()]
t = ii()
for _ in range(t):
	n = ii()
	a = iis()
	s = sum(a)
	if s % n != 0:
		print(-1)
		continue
	avgg = s // n
	print(len([i for i in a if i > avgg]))


t = int(input())
for z in range(t):
	n = int(input())
	li = [int(x) for x in input().split()]
	su = sum(li)
	if su % n == 0:
		k = su // n
		c = 0
		for i in range(n):
			if li[i] - k > 0:
				c = c + 1
		print(c)
	else:
		print('-1')


def Solve():
	Sum = Counter = 0
	for case in Cases:
		Sum += case
	if Sum % Size == 0:
		for case in Cases:
			if case > Sum / Size:
				Counter += 1
		return Results.append(Counter)
	else:
		return Results.append(-1)
TestCase = int(input(''))
Results = []
for c in range(TestCase):
	Size = int(input(''))
	Cases = list(map(int, input().split()))
	Solve()
for result in Results:
	print(result)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	if sum(arr) % n != 0:
		print(-1)
	else:
		cnt = 0
		avg = sum(arr) // n
		for i in arr:
			if i > avg:
				cnt += 1
		print(cnt)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = sum(a)
	if b % n != 0:
		print(-1)
	else:
		c = b // n
		res = 0
		for i in a:
			if i > c:
				res += 1
		print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = sum(a) / n
	if sum(a) % n != 0:
		b = -1
		print(b)
	elif n == 1 or max(a) == min(a):
		b = 0
		print(b)
	else:
		b = 0
		for i in a:
			if i > int(c):
				b += 1
		print(b)


from sys import stdin, stdout
case = int(stdin.readline())
for c in range(case):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	arr.sort()
	aver = sum(arr) / n
	if aver % 1 != 0:
		print(-1)
		continue
	aver = int(aver)
	need = 0
	dist = 0
	for ai in arr:
		if ai < aver:
			need += aver - ai
		else:
			break
	if need == 0:
		print(0)
		continue
	cnt = 0
	for i in range(n - 1, -1, -1):
		cnt += 1
		dist += arr[i] - aver
		if dist >= need:
			print(cnt)
			break


for t in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	if sum(a) % n != 0:
		print('-1')
	else:
		x = sum(a) // n
		c = 0
		for i in a:
			if i > x:
				c = c + 1
		print(c)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if sum(a) % n != 0:
		print(-1)
	else:
		(cnt, avg) = (0, sum(a) // n)
		for i in range(n):
			if a[i] > avg:
				cnt += 1
		print(cnt)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	s = sum(array)
	if s % n == 0:
		each_person = s // n
		ans = 0
		for i in array:
			if i > each_person:
				ans += 1
		print(ans)
	else:
		print(-1)


t = int(input())
answers = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if max(a) == min(a):
		answers.append(0)
	elif sum(a) % n == 0:
		count = 0
		tb = sum(a) / n
		for i in range(n):
			if a[i] > tb:
				count += 1
		answers.append(count)
	else:
		answers.append(-1)
for answer in answers:
	print(answer)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	S = sum(a)
	if S % n == 0:
		asn = 0
		for el in a:
			if el > S // n:
				asn += 1
		print(asn)
	else:
		print(-1)


t = int(input())
for e in range(t):
	n = int(input())
	l = input().split()
	for i in range(n):
		l[i] = int(l[i])
	su = sum(l)
	if su % n != 0:
		print(-1)
	else:
		div = su // n
		c = 0
		for i in l:
			if i > div:
				c += 1
		print(c)


import sys, math

def input():
	return sys.stdin.readline().rstrip('\n')

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	tot = sum(a)
	avg = tot / n
	if avg - math.ceil(avg) == 0:
		cnt = 0
		for i in a:
			if i > avg:
				cnt += 1
		print(cnt)
	else:
		print(-1)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	sum1 = sum(list1)
	if sum1 % n == 0:
		x = sum1 // n
		ans = 0
		for i in list1:
			if i > x:
				ans += 1
		print(ans)
	else:
		print(-1)


def solve(a):
	thisSum = sum(a)
	if thisSum % len(a) != 0:
		return -1
	count = 0
	target = thisSum // len(a)
	for i in a:
		if i > target:
			count += 1
	return count
t = int(input())
while t:
	n = int(input())
	a = [int(k) for k in input().split()]
	ans = solve(a)
	print(ans)
	t -= 1


css = int(input())
for zz in range(css):
	n = int(input())
	candies = [int(num) for num in input().split(' ')]
	total = sum(candies)
	if total % n != 0:
		print(-1)
	else:
		candies.sort()
		avg = total // n
		count = 0
		for candy in candies[::-1]:
			if candy > avg:
				count += 1
			else:
				break
		print(count)


import sys

def solve(n, candies):
	sum_ = sum(candies)
	if sum_ % n != 0:
		return -1
	target = sum_ // n
	ans = [num for num in candies if num > target]
	return len(ans)
t = int(sys.stdin.readline().strip())
for i in range(t):
	n = int(sys.stdin.readline().strip())
	line = sys.stdin.readline().strip()
	candies = list(map(int, line.split()))
	print(solve(n, candies))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if sum(a) % n:
		print(-1)
		continue
	a.sort()
	val = int(sum(a) / n)
	a.append(1 + val)
	i = 0
	while a[i] <= val:
		i += 1
	print(n - i)


def main(n, a):
	s = sum(a)
	if s % n != 0:
		print(-1)
	else:
		m = s / n
		print(len([i for i in a if i > m]))
for _ in range(int(input())):
	main(int(input()), list(map(int, input().split())))


import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	if m == 1:
		print(0)
		continue
	c = sum(a) / m
	if c != int(c):
		print(-1)
		continue
	c = int(c)
	p = 0
	for i in a:
		if i > c:
			p += 1
	print(p)


def process(a: list):
	N = len(a)
	total = sum(a)
	if total % N != 0:
		return -1
	else:
		required = total / N
		return sum((+1 if i > required else 0 for i in a))
t = int(input())
ans = []
for i in range(t):
	N = input()
	a = [int(v) for v in input().split(' ')]
	ans.append(process(a))
for i in ans:
	print(i)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	if min(x) == max(x):
		ans.append(0)
	elif sum(x) % len(x) != 0:
		ans.append(-1)
	else:
		avg = sum(x) // len(x)
		ans.append(sum(map(lambda i: i > avg, x)))
print(*ans, sep='\n')


import math
for i in range(int(input())):
	ans = 0
	n = int(input())
	list1 = list(map(int, input().split(' ')))
	sum1 = sum(list1)
	if int(math.floor(sum1 / n)) != sum1 / n:
		ans = -1
	else:
		for k in list1:
			if k > sum1 / n:
				ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = sum(l)
	if a % n != 0:
		print(-1)
	else:
		b = 0
		for i in range(n):
			if l[i] > a // n:
				b += 1
		print(b)


import math, sys, itertools
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in [wtf[i:i + 2] for i in range(1, len(wtf), 2)]:
	n = int(t[0])
	A = list(map(int, t[1].split()))
	sA = sum(A)
	if sA % n == 0:
		avg = sA // n
		tmp = [a for a in A if a > avg]
		print(len(tmp))
	else:
		print(-1)


import sys, copy
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	l = inlt()
	s = sum(l)
	ans = 0
	if s % n != 0:
		print(-1)
	else:
		m = s // n
		for i in range(n):
			if l[i] > m:
				ans += 1
		print(ans)


N = int(input())
j = 0
L = list()
while j < N:
	i = 0
	l = list()
	n = int(input())
	c = list(map(int, input().split()))
	L.append(c)
	j += 1
i = 0
Major = list()
while i < N:
	if sum(L[i]) % len(L[i]) != 0:
		Major.append(-1)
	else:
		a = sum(L[i]) / len(L[i])
		flag = 0
		for x in L[i]:
			if x > a:
				flag += 1
		Major.append(flag)
	i += 1
for x in Major:
	print(x)


from sys import stdin, stdout

def istr():
	return input()

def inum():
	return int(stdin.readline())

def imul():
	return map(int, stdin.readline().split())

def ilst():
	return list(map(int, stdin.readline().split()))

def splt():
	return list(stdin.readline().strip())

def emat(row):
	return [ilst() for i in range(row)]
max_itr = 100
from itertools import combinations
import math
for i in range(inum()):
	n = inum()
	a = ilst()
	summ = sum(a)
	mean = summ // n
	count = 0
	if summ % n != 0:
		print(-1)
	else:
		for i in range(n):
			if a[i] > mean:
				count += 1
		print(count)


import sys, os, io
from sys import stdin, stdout
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import bisect
import math
input = stdin.readline
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)

def dfs(node, vis, adj, lis):
	lis.append(node)
	vis[node] = 1
	for i in adj[node]:
		if vis[i] == 0:
			dfs(i, vis, adj, lis)

def dfsOfGraph(n, adj):
	lis = []
	vis = [0] * (n + 1)
	for i in range(1, n + 1):
		if vis[i] == 0:
			dfs(i, vis, adj, lis)
	return lis

def bfsOfGraph(n, adj):
	vis = [0] * (n + 1)
	lis = []
	for i in range(1, n + 1):
		if vis[i] == 0:
			queue = [i]
			vis[i] = 1
			while len(queue) > 0:
				node = queue.pop(0)
				lis.append(node)
				for j in adj[node]:
					if vis[j] == 0:
						queue.append(j)
						vis[j] = 1
	return lis
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	l = li()
	sm = sum(l)
	ft = sm // n
	if sm % n != 0:
		return -1
	res = 0
	for i in l:
		if i > ft:
			res += 1
	return res
t = ii()
for _ in range(t):
	res = solve()
	print(res)


def polycarp(n, arr):
	s = sum(arr)
	if s % n != 0:
		return -1
	x = 0
	y = s // n
	for i in range(n):
		if arr[i] > y:
			x += 1
	return x
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(polycarp(n, arr))


import sys
t = int(sys.stdin.readline())
while t > 0:
	n = sys.stdin.readline()
	a = list(map(int, sys.stdin.readline().split()))
	avg = int(sum(a) / len(a))
	if sum(a) % len(a) == 0:
		larger_elements = [element for element in a if element > avg]
		print(len(larger_elements))
	else:
		print(-1)
	t = t - 1


m = int(input())
otv = []
for _ in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a) // len(a)
	if sum(a) % len(a) != 0:
		c = -1
	else:
		c = 0
		for i in range(n):
			if a[i] > s:
				c += 1
	otv.append(c)
for i in range(m):
	print(otv[i])


import sys

def count_greater(arr, n):
	min = sys.maxsize
	counter = 0
	for i in range(len(arr)):
		if arr[i] > n:
			counter += 1
		else:
			break
	return counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % n != 0:
		print(-1)
	else:
		l.sort(reverse=True)
		x = s // n
		p = count_greater(l, x)
		print(p)


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	k = 0
	sum = 0
	for e in a:
		sum += e
	if sum % n != 0:
		k = -1
	else:
		av = sum // n
		for i in range(n):
			if a[i] > av:
				k += 1
	print(k)


def solve(x):
	lst = []
	lst = [int(lst) for lst in input().split()]
	sums = sum(lst)
	count = 0
	maincount = 0
	for i in range(0, len(lst)):
		if i != len(lst) - 1 and lst[i] == lst[i + 1]:
			count = count + 1
		elif i == len(lst):
			if lst[i] == lst[i - 1]:
				count = count + 1
	if sums % x == 0:
		value = sums // x
		for i in range(0, len(lst)):
			if lst[i] > value:
				maincount = maincount + 1
		print(maincount)
	elif len(lst) == 1 or count == len(lst):
		print(0)
	else:
		print(-1)
testcase = int(input())
while testcase > 0:
	x = int(input())
	solve(x)
	testcase = testcase - 1


def for_one_arr():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n != 0:
		print(-1)
	else:
		x = s // n
		cnt = 0
		for row in a:
			cnt += int(row > x)
		print(cnt)
t = int(input())
for i in range(t):
	for_one_arr()


from functools import reduce
t = int(input())
NO_of_candies_intially = []
final_answer = []

def functions(n):
	total_candies = reduce(lambda x, y: x + y, n)
	greater_no_candies_indices = []
	avg_candies_each_should_have = total_candies / len(n)
	if avg_candies_each_should_have == int(avg_candies_each_should_have):
		for i in range(len(n)):
			if n[i] > avg_candies_each_should_have:
				greater_no_candies_indices.append(i)
		k = len(greater_no_candies_indices)
		return k
	else:
		return -1
for tc in range(t):
	no_of_friends = int(input())
	NO_of_candies_intially = list(map(int, input().split(' ')))
	final_answer.append(functions(NO_of_candies_intially))
for r in final_answer:
	print(r)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	s = sum(arr)
	if s % n != 0:
		print(-1)
	else:
		avg = s // n
		ac = arr.count(avg)
		ans = 0
		for i in arr:
			if i > avg:
				ans += 1
		print(ans)


import math
import collections
from itertools import permutations
from itertools import combinations

def Infx():
	return float('inf')

def Infn():
	return float('-inf')

def prob():
	n = int(input())
	l = [int(x) for x in input().split()]
	if sum(l) % n != 0:
		print(-1)
	else:
		ans = 0
		p = sum(l) // n
		for i in l:
			if i > p:
				ans += 1
		print(ans)
t = 1
t = int(input())
for _ in range(0, t):
	prob()


def EqualDistribution(n):
	arr = list(map(int, input().split()))
	s = k = 0
	for i in range(n):
		s += arr[i]
	if s % n != 0:
		return -1
	else:
		p = s / n
	for i in range(n):
		if arr[i] > p:
			k += 1
	return k
t = int(input())
klist = []
for i in range(t):
	n = int(input())
	klist.append(EqualDistribution(n))
for i in range(t):
	print(klist[i])


s = 0
k = int(input())
while k > 0:
	ras = 0
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % n != 0:
		print(-1)
	else:
		for i in l:
			if i > s / n:
				ras = ras + 1
		print(ras)
	k -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	ll = list(map(int, input().split()))
	sumi = sum(ll)
	if sumi % n != 0:
		print(-1)
	else:
		for i in range(n):
			if ll[i] > sumi // n:
				count += 1
		print(count)


results = []
t = int(input())
for i in range(t):
	n = int(input())
	numbers = [int(x) for x in input().split(' ')]
	sum = 0
	for num in numbers:
		sum = sum + num
	opr = 0
	if sum % n == 0:
		mean = sum / n
		for num in numbers:
			if num > mean:
				opr = opr + 1
		results.append(opr)
	else:
		results.append(-1)
for res in results:
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	s = 0
	a = [int(i) for i in input().split()]
	for i in a:
		s += i
	if s % n != 0:
		print(-1)
	elif n == 1:
		print(0)
	elif len(list(set(a))) == 1:
		print(0)
	else:
		c = 0
		p = s // n
		for i in a:
			if i > p:
				c += 1
		print(c)


t = int(input())
res = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % n != 0:
		res.append(-1)
		continue
	elif n == 1:
		res.append(0)
		continue
	avg = s // n
	k = 0
	for i in range(n):
		if a[i] > avg:
			k += 1
	res.append(k)
for r in res:
	print(r)


t = int(input())

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % n != 0:
		print(-1)
		return
	same = s // n
	offset = 0
	for i in arr:
		offset += abs(i - same)
	arr.sort()
	arr.reverse()
	if offset == 0:
		print(0)
		return
	count = 0
	for i in arr:
		offset -= 2 * (i - same)
		count += 1
		if offset <= 0:
			break
	print(count)
for i in range(t):
	solve()


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor
cases = int(input())
for _ in range(cases):
	num = int(input())
	arr = list(map(int, input().split()))
	sm = sum(arr)
	if len(set(arr)) == 1:
		print(0)
	elif sm % num != 0:
		print(-1)
	else:
		md = sm // num
		ans = sum((1 for i in arr if i > md))
		print(ans)


def rearrange(candies):
	(avg, rem) = divmod(sum(candies), len(candies))
	if rem > 0:
		return -1
	res = len([c for c in candies if c > avg])
	return res
N = int(input())
for n in range(N):
	t = input()
	candies = [int(c) for c in input().split()]
	print(rearrange(candies))