Polycarp was given an array of $a[1 \dots n]$ of $n$ integers. He can perform the following operation with the array $a$ no more than $n$ times:

Polycarp selects the index $i$ and adds the value $a_i$ to one of his choice of its neighbors. More formally, Polycarp adds the value of $a_i$ to $a_{i-1}$ or to $a_{i+1}$ (if such a neighbor does not exist, then it is impossible to add to it).

After adding it, Polycarp removes the $i$-th element from the $a$ array. During this step the length of $a$ is decreased by $1$.

The two items above together denote one single operation.

For example, if Polycarp has an array $a = [3, 1, 6, 6, 2]$, then it can perform the following sequence of operations with it:

Polycarp selects $i = 2$ and adds the value $a_i$ to $(i-1)$-th element: $a = [4, 6, 6, 2]$.

Polycarp selects $i = 1$ and adds the value $a_i$ to $(i+1)$-th element: $a = [10, 6, 2]$.

Polycarp selects $i = 3$ and adds the value $a_i$ to $(i-1)$-th element: $a = [10, 8]$.

Polycarp selects $i = 2$ and adds the value $a_i$ to $(i-1)$-th element: $a = [18]$.

Note that Polycarp could stop performing operations at any time.

Polycarp wondered how many minimum operations he would need to perform to make all the elements of $a$ equal (i.e., he wants all $a_i$ are equal to each other).


-----Input-----

The first line contains a single integer $t$ ($1 \leq t \leq 3000$) — the number of test cases in the test. Then $t$ test cases follow.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 3000$) — the length of the array. The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^5$) — array $a$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $3000$.


-----Output-----

For each test case, output a single number — the minimum number of operations that Polycarp needs to perform so that all elements of the $a$ array are the same (equal).


-----Examples-----

Input
4
5
3 1 6 6 2
4
1 2 2 1
3
2 2 2
4
6 3 2 1
Output
4
2
0
2


-----Note-----

In the first test case of the example, the answer can be constructed like this (just one way among many other ways):

$[3, 1, 6, 6, 2]$ $\xrightarrow[]{i=4,~add~to~left}$ $[3, 1, 12, 2]$ $\xrightarrow[]{i=2,~add~to~right}$ $[3, 13, 2]$ $\xrightarrow[]{i=1,~add~to~right}$ $[16, 2]$ $\xrightarrow[]{i=2,~add~to~left}$ $[18]$. All elements of the array $[18]$ are the same.

In the second test case of the example, the answer can be constructed like this (just one way among other ways):

$[1, 2, 2, 1]$ $\xrightarrow[]{i=1,~add~to~right}$ $[3, 2, 1]$ $\xrightarrow[]{i=3,~add~to~left}$ $[3, 3]$. All elements of the array $[3, 3]$ are the same.

In the third test case of the example, Polycarp doesn't need to perform any operations since $[2, 2, 2]$ contains equal (same) elements only.

In the fourth test case of the example, the answer can be constructed like this (just one way among other ways):

$[6, 3, 2, 1]$ $\xrightarrow[]{i=3,~add~to~right}$ $[6, 3, 3]$ $\xrightarrow[]{i=3,~add~to~left}$ $[6, 6]$. All elements of the array $[6, 6]$ are the same.

Source: codeforces | Difficulty: MEDIUM
Tags: Number theory

Mathematics

Greedy algorithms


Solutions:
from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

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

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
ha = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
while t:
	t -= 1
	n = inp()
	a = lis()
	fl = 0
	ma = 10000000000
	for i in range(n):
		cs = sum(a[:i + 1])
		mo = i
		cu = 0
		lf = 1
		for j in range(i + 1, n):
			cu += a[j]
			if cu == cs:
				cu = 0
			if cu > cs:
				lf = 0
				break
			elif cu != 0:
				mo += 1
		if lf and cu == 0:
			ma = min(ma, mo)
	print(ma)


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if sum(l) % (n - i) == 0:
			curr = 0
			x = sum(l) / (n - i)
			for j in range(n):
				curr += l[j]
				if curr == x:
					curr = 0
				elif curr > x:
					break
			if curr == 0:
				ans = i
				break
			else:
				continue
	print(ans)


def get_ints():
	return [int(x) for x in input().split()]
t = int(input())
for _ in range(t):
	n = int(input())
	A = get_ints()
	As = sum(A)
	for c in range(n, 0, -1):
		if As % c == 0:
			ds = As // c
			good = True
			s = 0
			for j in range(n):
				s += A[j]
				if s == ds:
					s = 0
				elif s > ds:
					good = False
					break
			if good:
				print(n - c)
				break


def solve():
	n = int(input())
	ll = list(map(int, input().split()))
	sm = sum(ll)
	for i in range(n):
		if sm % (n - i) == 0:
			val = sm // (n - i)
			temp_sm = 0
			flag = 0
			for j in range(n):
				temp_sm += ll[j]
				if temp_sm == val:
					temp_sm = 0
				elif temp_sm > val:
					flag = 1
					break
			if not flag:
				return i
	return n
t = int(input())
while t != 0:
	res = solve()
	print(res)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	v = [int(x) for x in input().split()]
	sm = sum(v)
	ans = 0

	def fn(target):
		sx = 0
		for x in v:
			sx += x
			if sx == target:
				sx = 0
			elif sx > target:
				return False
		return True
	for i in range(1, n + 1):
		if sm % i:
			continue
		if fn(sm // i):
			ans = i
	print(n - ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split(' ')))
	s = sum(A)
	i = n
	while i >= 1:
		if s % i == 0:
			needsum = s / i
			cursum = 0
			ok = True
			for j in range(n):
				cursum += A[j]
				if cursum > needsum:
					ok = False
					break
				elif cursum == needsum:
					cursum = 0
			if ok:
				print(n - i)
				break
		i -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	summ = sum(a)
	for k in range(n, 0, -1):
		if summ % k != 0:
			continue
		each = summ // k
		curr = 0
		flag = True
		for i in a:
			curr += i
			if curr > each:
				flag = False
				break
			if curr == each:
				curr = 0
		if flag == True:
			print(n - k)
			break


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	min_ans = 0
	while True:
		chk = True
		avg_ans = s / (n - min_ans)
		curr_sum = 0
		for i in range(n):
			if curr_sum < avg_ans:
				curr_sum += a[i]
			if curr_sum == avg_ans:
				curr_sum = 0
			elif curr_sum > avg_ans:
				chk = False
				min_ans += 1
				break
		if chk == True:
			print(min_ans)
			break


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = list(read_ints())
	part = 0
	s = sum(a)
	found = False
	for i in range(n - 1):
		part += a[i]
		if s % part != 0:
			continue
		valid = True
		curr = 0
		for j in range(i + 1, n):
			if curr + a[j] > part:
				valid = False
				break
			elif curr + a[j] == part:
				curr = 0
			else:
				curr += a[j]
		if valid:
			print(n - s // part)
			found = True
			break
	if not found:
		print(n - 1)


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	n = inn()
	a = arr()
	till = 0
	ans = inf
	for i in range(n):
		till += a[i]
		val = 0
		res = []
		for j in range(n):
			if val < till:
				val += a[j]
			else:
				res.append(val)
				val = a[j]
		res.append(val)
		if len(set(res)) == 1:
			ans = min(ans, n - len(res))
	print(ans)


from collections import Counter

def solve(a):
	n = len(a)
	Sum = sum(a)
	for i in range(n):
		if check(Sum, len(a), i):
			return i

def check(Sum, n, x):
	x = n - x
	if Sum % x != 0:
		return False
	cur = 0
	for i in range(len(a)):
		cur += a[i]
		if cur == Sum / x:
			cur = 0
		elif cur > Sum / x:
			return False
	if cur == 0:
		return True
	else:
		return False
t = int(input(''))
ans = []
while t > 0:
	n = int(input(''))
	a = list(map(int, input('').split(' ')))
	ans.append(solve(a))
	t -= 1
for i in ans:
	print(i)


def check(arr, n, K, prefix_sum):
	total_sum = prefix_sum[n - 1]
	if total_sum % K != 0:
		return False
	temp = 0
	pos = -1
	for i in range(0, n, 1):
		if pos == -1:
			sub = 0
		else:
			sub = prefix_sum[pos]
		if prefix_sum[i] - sub == total_sum / K:
			pos = i
			temp += 1
		elif prefix_sum[i] - prefix_sum[pos] > total_sum / K:
			break
	return temp == K
for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	prefix_sum = [0 for i in range(n)]
	prefix_sum[0] = l[0]
	for i in range(1, n, 1):
		prefix_sum[i] = prefix_sum[i - 1] + l[i]
	for j in range(n, 0, -1):
		if check(l, n, j, prefix_sum):
			print(n - j)
			break


def solve(a):
	n = len(a)
	s = sum(a)
	for d in reversed(range(1, n + 1)):
		if s % d != 0:
			continue
		sum_needed = s // d
		sum_current = 0
		ok = True
		for x in a:
			sum_current += x
			if sum_current > sum_needed:
				ok = False
				break
			elif sum_current == sum_needed:
				sum_current = 0
		if ok:
			return n - d
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	print(solve(a))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = 0
	rs = n - 1
	for i in range(n):
		s += a[i]
		s1 = 0
		cnt = i
		ok = 1
		for j in range(i + 1, n):
			s1 += a[j]
			if s1 > s:
				ok = 0
				break
			if s1 == s:
				s1 = 0
			else:
				cnt += 1
		if s1 != 0:
			ok = 0
		if ok == 1:
			rs = min(rs, cnt)
	print(rs)


import sys
import bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

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

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 9
	n = random.randint(1, N)
	m = random.randint(1, n * n)
	A = [random.randint(1, n) for i in range(m)]
	B = [random.randint(1, n) for i in range(m)]
	G = [[] for i in range(n)]
	RG = [[] for i in range(n)]
	for i in range(m):
		(a, b) = (A[i] - 1, B[i] - 1)
		if a == b:
			continue
		G[a] += ((b, 1),)
		RG[b] += ((a, 1),)
	return (n, m, G, RG)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 == a2:
			print(inp)
			print('naive', a1)
			print('solve', a2)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True

def primeFactor(N):
	(i, n) = (2, N)
	ret = {}
	(d, sq) = (2, 99)
	while i <= sq:
		k = 0
		while n % i == 0:
			(n, k, ret[i]) = (n // i, k + 1, k + 1)
		if k > 0 or i == 97:
			sq = int(n ** (1 / 2) + 0.5)
		if i < 4:
			i = i * 2 - 1
		else:
			(i, d) = (i + d, d ^ 6)
	if n > 1:
		ret[n] = 1
	return ret

def divisor(n):
	div = [1]
	for (i, j) in primeFactor(n).items():
		div = [i ** k * d for d in div for k in range(j + 1)]
	return div

def PrimeNumSet(N):
	M = int(N ** 0.5)
	seachList = [i for i in range(2, N + 1)]
	primes = []
	while seachList:
		if seachList[0] > M:
			break
		primes.append(seachList[0])
		tmp = seachList[0]
		seachList = [i for i in seachList if i % tmp != 0]
	return primes + seachList

def LCM(b, mo=10 ** 9 + 7):
	prs = PrimeNumSet(max(b))
	M = dict(zip(prs, [0] * len(prs)))
	for i in b:
		dc = primeFactor(i)
		for (j, k) in dc.items():
			M[j] = max(M[j], k)
	r = 1
	for (j, k) in M.items():
		if k != 0:
			r *= pow(j, k, mo)
			r %= mo
	return r
ans = 0
for _ in range(I()):
	n = I()
	a = LI()
	z = sum(a)
	ans = inf
	for d in divisor(z):
		f = True
		t = 0
		tmp = 0
		for i in range(n):
			t += a[i]
			if t == d:
				t = 0
			elif t > d:
				tmp = inf
				f = False
				break
			else:
				tmp += 1
				pass
		if f:
			ans = min(ans, tmp)
		else:
			continue
	print(ans)


import bisect
T = int(input())
for t in range(T):
	N = int(input())
	arr = [int(k) for k in input().split()]

	def valid(limit):
		tmp = 0
		for i in range(0, N):
			tmp += arr[i]
			if tmp == limit:
				tmp = 0
			elif tmp > limit:
				return False
		if tmp == 0:
			return True
		return False
	tot = sum(arr)
	max_seg = 0
	for seg in range(1, N + 1):
		if tot % seg == 0:
			if valid(tot // seg):
				max_seg = max(max_seg, seg)
	print(N - max_seg)


t = int(input())

def check(M, l):
	s = 0
	oper = 0
	for elem in l:
		s += elem
		if s == M:
			s = 0
		elif s < M:
			oper += 1
		else:
			return -1
	if s != M and s != 0:
		return -1
	return oper
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	M = 0
	op = float('inf')
	for (i, v) in enumerate(l):
		M += v
		op2 = check(M, l)
		if op2 != -1:
			op = min(op, op2)
	print(op)


for s in [*open(0)][2::2]:
	a = [0]
	for x in s.split():
		a += (a[-1] + int(x),)
	s = a[-1]
	t = {*a}
	n = k = len(a) - 1
	while s % k or not {*range(0, s, s // k)} <= t:
		k -= 1
	print(n - k)


import math

def factor(n):
	s = set()
	s.add(n)
	s.add(1)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			s.add(i)
			s.add(n // i)
	return s
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sumi = sum(a)
	fac = list(factor(sumi))
	fans = 10 ** 9
	for i in range(0, len(fac)):
		count = 0
		f = 0
		size = 0
		z = fac[i]
		ans = 0
		for j in range(0, len(a)):
			ans += a[j]
			size += 1
			if ans == z:
				count += size - 1
				size = 0
				ans = 0
			if ans > z:
				f = 1
				break
		if f == 0:
			fans = min(fans, count)
	print(fans)


import sys, itertools
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	m = sum(arr)
	for i in range(n, 0, -1):
		if m % i == 0:
			target = m // i
			temp = 0
			can = True
			for j in range(n):
				temp += arr[j]
				if temp > target:
					can = False
					break
				elif temp == target:
					temp = 0
			if can:
				print(n - i)
				break


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = []
	s = 0
	for e in a:
		s += e
		p.append(s)
	for i in range(n):
		if s % p[i] != 0:
			continue
		flag = True
		temp = 2 * p[i]
		for j in range(i + 1, n):
			if p[j] > temp:
				flag = False
				break
			if p[j] == temp:
				temp += p[i]
		if flag:
			print(n - s // p[i])
			break


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	i = 0
	j = n - 1
	sleft = 0
	sright = 0
	sleftarr = []
	srightarr = []
	for i in range(n):
		sleft += a[i]
		sleftarr.append(sleft)
	for i in reversed(range(n)):
		sright += a[i]
		srightarr.append(sright)
	srightarr.reverse()
	for i in range(n):
		for j in range(i + 1, n):
			sleft = sleftarr[i]
			sright = srightarr[j]
			if sleft == sright and (s - 2 * sleft) % sleft == 0:
				x = i + 1
				f = 0
				sval = 0
				while x < j:
					sval += a[x]
					if sval == sleft:
						sval = 0
						if x == j - 1:
							f = 1
					elif sval > sleft:
						break
					x += 1
				if f == 1:
					count = s // sleft
					print(n - count)
					return
			if sleft == sright and i + 1 == j:
				print(n - 2)
				return
	print(n - 1)
	return

def main():
	testcases = 1
	testcases = int(input())
	for _ in range(testcases):
		solution()
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')
main()


import math

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

def di(x):
	d = {}
	for i in x:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	return d

def ma(x):
	return math.log2(x)

def ce(x):
	return math.ceil(x)

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

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

def ii():
	return int(input())
for _ in range(ii()):
	n = ii()
	l = lis()
	(s, x, f) = (0, sum(l), False)
	for i in l:
		s += i
		ans = 0
		for j in l:
			ans += j
			if ans == s:
				ans = 0
			if ans > s:
				break
		if ans == 0:
			f = True
			break
	if f:
		print(n - x // s)
	else:
		print(-1)


def check(a, m):
	n = len(a)
	S = sum(a)
	if m >= n - 1:
		return True
	elif S % (n - m) != 0:
		return False
	else:
		x = S // (n - m)
		i = 0
		r = 0
		c = 0
		while i < n:
			r += a[i]
			if 0 < r < x:
				c += 1
			elif r == x:
				r = 0
			else:
				return False
			i += 1
		if r or c != m:
			return False
		else:
			return True
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	for i in range(n):
		if check(a, i):
			print(i)
			break


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	f = 0
	c = 0
	if len(set(l)) == 1:
		print(0)
	else:
		for i in range(1, n + 1):
			s = sum(l[:i])
			t = 0
			for j in range(n):
				t = t + l[j]
				if t == s:
					t = 0
			if t == 0:
				print(n - sum(l) // s)
				break


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		s = sum(a)
		p = []
		for j in range(1, int(math.sqrt(s)) + 1):
			if s % j == 0:
				p.append(j)
				if j * j != s:
					p.append(s // j)
		p.sort()
		ans = 0
		for x in p:
			r = 0
			f = True
			cnt = 0
			while r < n:
				if a[r] > x:
					f = False
					break
				tmp = x
				while r < n:
					tmp = tmp - a[r]
					r += 1
					if tmp <= 0:
						break
					cnt += 1
				if tmp != 0:
					f = False
					break
			if f:
				ans = cnt
				break
		print(ans)
main()


def solution(n, a):
	opercnt = 0
	s = sum(a)
	mincnt = -1
	while opercnt < n:
		if s % (n - opercnt) != 0:
			opercnt += 1
			continue
		cursum = 0
		avg = s / (n - opercnt)
		issuccess = True
		for i in a:
			cursum += i
			if cursum > avg:
				issuccess = False
				break
			if cursum == avg:
				cursum = 0
		if issuccess:
			mincnt = opercnt
			break
		opercnt += 1
	return mincnt
t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solution(n, a))


def get_div_list(factors, fct=[], div_list=[]):
	if len(factors) == 0:
		divisor = 1
		for x in fct:
			divisor *= x
		return div_list + [divisor]
	div_list = []
	new_factor_list = factors[1:]
	used_factor = factors[0]
	new_fct = fct
	div_list += get_div_list(new_factor_list, new_fct)
	new_fct = fct + [used_factor]
	div_list += get_div_list(new_factor_list, new_fct)
	return div_list
t = int(input())
for _ in range(t):
	n = int(input())
	a_str = str(input()).split(' ')
	a_list = []
	a_sum = 0
	for a_i in a_str:
		a_int = int(a_i)
		a_list.append(a_int)
		a_sum += a_int
	factors = []
	remainder = a_sum
	half_reached = False
	while not half_reached and remainder > 1:
		for i in range(2, int(remainder / 2) + 2):
			if remainder % i == 0:
				remainder = remainder / i
				factors.append(i)
				break
			if i == int(remainder / 2) + 1:
				half_reached = True
			if remainder / (i - 1) < i:
				half_reached = True
	if remainder > 1:
		factors.append(int(remainder))
		remainder = 1
	factors = sorted(factors)
	divisor = a_sum
	every_a = int(a_sum / divisor)
	div_list = get_div_list(factors)
	div_list = sorted(list(set(div_list)))
	div_list = div_list[:-1]
	conf = False
	while not conf:
		if a_sum % divisor == 0:
			a_sum_count = 0
			for idx in range(len(a_list)):
				a_i = a_list[idx]
				a_sum_count += a_i
				if a_sum_count > every_a:
					divisor = div_list[-1]
					div_list = div_list[:-1]
					every_a = int(a_sum / divisor)
					break
				elif a_sum_count == every_a:
					a_sum_count = 0
				if idx == len(a_list) - 1 and a_sum_count == 0:
					conf = True
		else:
			divisor = div_list[-1]
			div_list = div_list[:-1]
			every_a = int(a_sum / divisor)
	print(len(a_list) - divisor)


def main():
	for _ in range(int(input())):
		(n, a, l) = (int(input()), 0, [])
		for b in map(int, input().split()):
			a += b
			l.append(a)
		s = set(l)
		for b in l:
			if not a % b and all((x in s for x in range(b * 2, a + 1, b))):
				print(n - a // b)
				break
main()


import sys
import math, bisect, operator
(inf, m) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	A = Neo()

	def check(t):
		i = 0
		k = 0
		while i < n:
			k += A[i]
			if k == t:
				k = 0
			elif k > t:
				return 0
			i += 1
		if k == t or k == 0:
			return 1
		return 0
	t = sum(A)
	div = set()
	for i in range(1, int(t ** 0.5) + 1):
		if t % i == 0:
			div.add(i)
			div.add(t // i)
	for i in sorted(div):
		if check(i):
			print(n - t // i)
			break


import sys
import os
from io import BytesIO, IOBase
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

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, lst):
	preS = [lst[0]]
	for i in range(1, n):
		preS.append(preS[-1] + lst[i])
	ans = float('inf')
	for j in preS:
		poss = True
		currS = [0]
		for i in range(n):
			currS[-1] += lst[i]
			if currS[-1] == j:
				currS.append(0)
			elif currS[-1] > j:
				poss = False
				break
		if poss and (currS[-1] == 0 or currS[-1] == j):
			val = len(lst) - (len(currS) - 1)
			ans = min(ans, val)
	if ans == float('inf'):
		return n - 1
	return ans
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	come = 0
	counti = 0
	a = max(l)
	summm = sum(l)
	j = 0
	sumi = 0
	for i in range(len(l)):
		sumi += l[i]
		if sumi >= a:
			a = sumi
			j = i + 1
			break
	while come == 0:
		if summm % a == 0:
			counti = 0
			come = 0
			sumi = 0
			for i in range(n):
				sumi += l[i]
				if sumi > a:
					come = 1
					break
				elif sumi == a:
					counti += 1
					sumi = 0
			if come == 1 or sumi != 0:
				come = 0
				if j != n - 1:
					a += l[j]
					j += 1
				else:
					counti = 1
					break
			else:
				come = 1
		elif j != n - 1:
			a += l[j]
			j += 1
		else:
			counti = 1
			break
	print(n - counti)


import sys
input = sys.stdin.readline

def check(o):
	m = s / o
	lc = l.copy()
	for el in range(n):
		if lc[0] == m:
			lc.pop(0)
		elif lc[0] < m:
			lc[1] = lc[1] + lc[0]
			lc.pop(0)
		else:
			return False
	return True
for _ in range(int(input())):
	n = int(input().strip())
	l = [*map(int, input().strip().split())]
	s = sum(l)
	i = n
	while i >= 1:
		if s % i == 0:
			if check(i):
				print(n - i)
				break
		i -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(5 * 10 ** 5)
inf = 10 ** 20
mod = 10 ** 9 + 7
from math import gcd

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

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def cut_l(a_list, p_sum):
	cnt = 0
	i = 0
	tmp_sum = 0
	while i < len(a_list):
		tmp_sum += a_list[i]
		if tmp_sum == p_sum:
			cnt += 1
			tmp_sum = 0
		elif tmp_sum > p_sum:
			return -1
		i += 1
	return cnt

def solve():
	n = II()
	a_list = LI()
	ans = n - 1
	p_sum = 0
	a_sum = sum(a_list)
	for i in range(n - 1):
		p_sum += a_list[i]
		if a_sum % p_sum:
			continue
		cut_cnt = cut_l(a_list, p_sum)
		if cut_cnt == -1:
			continue
		else:
			ans = min(ans, n - cut_cnt)
	return ans

def main():
	t = II()
	res = list()
	for _ in range(t):
		res.append(solve())
	for ans in res:
		print(ans)
	return 0
main()


import sys
input = sys.stdin.readline

def solution(n, arr):
	partial_sums = [arr[0]]
	s_p_s = set()
	total = 0
	for elem in arr[1:]:
		partial_sums.append(partial_sums[-1] + elem)
	total = partial_sums[-1]
	s_p_s = set(partial_sums)
	for ps in partial_sums[0:-1]:
		if total % ps == 0:
			correct = True
			for mult in range(2 * ps, total, ps):
				if mult not in s_p_s:
					correct = False
					break
			if correct:
				nb_groups = total // ps
				print(n - nb_groups)
				return
	print(n - 1)
T = int(input())
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	solution(n, arr)


import math

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	s = sum(a)
	divs = set([s])
	for i in range(1, int(math.sqrt(s)) + 2):
		if s % i == 0:
			divs.add(i)
			divs.add(int(s / i))
	divs = sorted(list(divs))
	mmin = n - 1
	for i in divs:
		cur_s = i
		good = True
		step = 0
		for j in a:
			cur_s -= j
			if cur_s < 0:
				good = False
				break
			elif cur_s == 0:
				cur_s = i
			else:
				step += 1
		if good and mmin > step and (cur_s == i):
			mmin = step
	print(mmin)
[solve() for _ in range(int(input()))]


T = int(input())
for test in range(T):
	n = int(input())
	ans = n
	x = input().split(' ')
	for i in range(n):
		x[i] = int(x[i])
	con = 0
	for i in range(n):
		con += x[i]
		now_ans = i
		nows = 0
		cnt = 0
		flag = 1
		for j in range(i + 1, n):
			if nows != con and nows + x[j] > con:
				flag = 0
				break
			if nows + x[j] <= con:
				nows += x[j]
				cnt += 1
			if nows == con:
				now_ans += cnt - 1
				nows = 0
				cnt = 0
		if flag and nows == 0:
			ans = min(ans, now_ans)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	sum_num = sum(num)
	for k in range(n, 0, -1):
		if sum_num % k != 0:
			continue
		flag = True
		each_sum = sum_num // k
		curr_sum = 0
		for number in num:
			curr_sum += number
			if curr_sum > each_sum:
				flag = False
				break
			elif curr_sum == each_sum:
				curr_sum = 0
		if flag:
			print(n - k)
			break


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(sum1, ans, f2) = (sum(l), n - 1, 0)
	for k in range(0, n):
		if sum1 % (n - k) == 0:
			x = sum1 / (n - k)
			(cur, f1) = (0, 0)
			for j in range(len(l)):
				cur += l[j]
				if cur == x:
					cur = 0
				elif cur > x:
					f1 = 1
					break
			if f1 == 0:
				ans = k
				f2 = 1
				break
	print(ans)


import copy
import math
t = int(input())
for case in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	s = sum(l)
	for i in range(n, 0, -1):
		if s % i == 0:
			key = s // i
			k = 0
			sums = 0
			while k < n:
				while k < n and sums < key:
					sums += l[k]
					k += 1
				if sums > key:
					break
				if k == n:
					break
				if sums == key:
					sums = 0
			if sums == key and k == n:
				print(n - i)
				break


def get_dels(n, M):
	dels = {n}
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			if i >= M:
				dels.add(i)
			if n // i >= M:
				dels.add(n // i)
		i += 1
	return sorted(dels)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0]
	M = -float('inf')
	for i in a:
		b.append(b[-1] + i)
		M = max(i, M)
	dels = get_dels(b[-1], M)
	if all([a[0] == i for i in a]):
		print(0)
		continue
	for d in dels:
		count = b[-1] // d
		ans = n - count
		if count == 1:
			print(ans)
		else:
			start = 0
			for j in range(n):
				if b[j + 1] - b[start] == d:
					count -= 1
					start = j + 1
			if start >= n and count == 0:
				print(ans)
				break


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	asum = sum(a)
	ans = -1
	for i in range(n, 0, -1):
		if asum % i == 0:
			temp = asum // i
			curr = 0
			flag = True
			for j in range(n):
				curr += a[j]
				if curr > temp:
					flag = False
					break
				elif curr == temp:
					curr = 0
			if flag:
				ans = n - i
				break
	print(ans)


import os
import sys
from io import BytesIO, IOBase
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()

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

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	a = RLL()
	dic = set()
	s = 0
	for v in a:
		s += v
		dic.add(s)
	for k in range(n, 0, -1):
		if s % k:
			continue
		(flag, p, now) = (True, s // k, 0)
		for _ in range(k - 1):
			now += p
			if now not in dic:
				flag = False
				break
		if flag:
			print(n - k)
			break


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	s = sum(nums)
	ans = 0
	for no_of_elements in range(n, 0, -1):
		if s % no_of_elements == 0:
			sum_target = s // no_of_elements
			count = 0
			possible = True
			i = 0
			while i < n:
				cur_sum = 0
				while i < n and cur_sum < sum_target:
					cur_sum += nums[i]
					i += 1
				count += 1
				if cur_sum != sum_target:
					possible = False
					break
			if possible and count == no_of_elements:
				ans = count
				break
	print(n - count)
	pass


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	s = sum(array)
	if array.count(array[0]) == len(array):
		print(0)
	else:
		for k in range(1, n):
			m = []
			m.extend(array)
			t = s // (n - k)
			if s % (n - k) != 0:
				continue
			else:
				z = 0
				j = 0
				while j < len(array) - 1 and z != k:
					if m[j] == t:
						j += 1
					else:
						m[j + 1] += m[j]
						m.pop(j)
						z += 1
				if m.count(m[0]) == n - k:
					print(k)
					break


for u in range(int(input())):
	n = int(input())
	x = [int(w) for w in input().split()]
	s = sum(x)
	ans = 0
	for i in range(n, 0, -1):
		if s % i == 0:
			r = s // i
			c = 0
			f = True
			for j in range(n):
				c += x[j]
				if c == r:
					c = 0
				elif c > r:
					f = False
					break
			if f:
				ans = n - i
				break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	tot = sum(l)
	for i in range(n, 0, -1):
		flagg = 1
		if tot % i == 0:
			flag = 1
			add = 0
			for j in l:
				if add + j == tot // i:
					add = 0
				elif add + j < tot // i:
					add += j
				else:
					flag = 0
					break
			if add == 0 and flag == 1:
				print(n - i)
				falgg = 0
				break
		if flagg == 0:
			break


def tong(arr, number):
	if len(arr) == 0:
		return True
	ans = 0
	for i in arr:
		ans += i
		if ans == number:
			ans = 0
		elif ans > number:
			return False
		else:
			continue
	if ans == 0:
		return True
	else:
		return False
n = int(input())
for _ in range(n):
	m = int(input())
	arr = list(map(int, input().split()))
	total = sum(arr)
	lmao = 0
	for i in arr:
		lmao += i
		if total % lmao == 0:
			if tong(arr, lmao):
				break
			else:
				continue
		else:
			continue
	print(m - total // lmao)


from sys import stdin
stdin.readline

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

def it():
	return int(stdin.readline().strip())
from math import ceil

def check(l, k):
	s = 0
	ans = 0
	n = len(l)
	j = 0
	for i in range(n):
		s += l[i]
		if s == k:
			ans += i - j
			j = i + 1
			s = 0
		elif s > k:
			return -1
	return ans
for _ in range(it()):
	n = it()
	l = mp()
	s = sum(l)
	i = 1
	ans = n - 1
	while i * i <= s:
		if s % i == 0:
			a1 = check(l, i)
			a2 = check(l, s // i)
		i += 1
		if a1 != -1:
			ans = min(ans, a1)
		if a2 != -1:
			ans = min(ans, a2)
	print(ans)


from sys import stdin
inp = stdin.read()
lst = list(map(int, inp.split()))
t = lst[0]
s = 1
for _ in range(t):
	n = lst[s]
	s += 1
	seq = lst[s:s + n]
	totsum = 0
	totop = n

	def ver(x, l):
		actsum = 0
		op = 0
		for i in l:
			if actsum < x:
				actsum += i
			if actsum == x:
				actsum = 0
			else:
				op += 1
			if actsum > x:
				return n
		return op if actsum == 0 else n
	for i in seq:
		totsum += i
		if sum(seq) % totsum == 0:
			totop = min(totop, ver(totsum, seq))
	print(totop)
	s += n


t = int(input())

def is_possible(target_subarray_sum, prefix_sums, n):
	ptr = 0
	curr_accum = 0
	num_arrays = 0
	while ptr < n:
		if prefix_sums[ptr] - curr_accum < target_subarray_sum:
			pass
		elif prefix_sums[ptr] - curr_accum > target_subarray_sum:
			return (False, -1)
		elif prefix_sums[ptr] - curr_accum == target_subarray_sum:
			curr_accum += target_subarray_sum
			num_arrays += 1
		ptr += 1
	return (True, num_arrays)
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	total_sum = sum(arr)
	subarray_sum = total_sum
	num_subarrays = n
	prefix_sums = {}
	curr_prefix = 0
	for i in range(n):
		curr_prefix += arr[i]
		prefix_sums[i] = curr_prefix
	while num_subarrays >= 0:
		if subarray_sum % num_subarrays == 0:
			t = is_possible(subarray_sum // num_subarrays, prefix_sums, n)
			if t[0]:
				print(f'{n - num_subarrays}')
				break
		num_subarrays -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	for i in range(n, 0, -1):
		if s % i == 0:
			needs = s / i
			curs = 0
			ok = True
			for j in range(n):
				curs += a[j]
				if curs > needs:
					ok = False
					break
				elif curs == needs:
					curs = 0
			if ok:
				print(n - i)
				break


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


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	m = max(a)
	i = n
	while i > 1:
		if s % i != 0 or s // i < m:
			i -= 1
			continue
		aim = s // i
		curr = 0
		cnt = 0
		for j in range(n):
			curr += a[j]
			if curr > aim:
				break
			elif curr == aim:
				curr = 0
				cnt += 1
		else:
			print(n - i)
			break
		i -= 1
	else:
		print(n - 1)


for i in range(int(input())):
	length = int(input())
	ls = list(map(int, input().split()))
	if len(ls) == 1 or ls.count(ls[0]) == len(ls):
		print(0)
	else:
		res = len(ls) - 1
		s = sum(ls)
		for i in range(length - 1, 1, -1):
			if s % i == 0:
				cur = 0
				need = s // i
				ans = 0
				flag = 1
				for j in range(len(ls)):
					cur += ls[j]
					if cur > need:
						flag = 0
						break
					elif cur == need:
						cur = 0
				if flag == 1:
					res = length - i
					break
		print(res)


t = int(input())
while t:
	n = int(input().rstrip())
	a = list(map(int, input().split()))
	Sum = sum(a)
	ans = float('inf')
	for i in range(1, n + 1):
		if Sum % i == 0:
			block = Sum // i
			j = 0
			blocks = 0
			T = True
			while i > blocks:
				s = 0
				while block > s:
					s += a[j]
					j += 1
				if block == s:
					blocks += 1
				else:
					T = False
					break
			if T:
				ans = n - i
	print(ans)
	t -= 1


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)

def output(answer):
	stdout.write(str(answer))
num = int(z())
for _ in range(num):
	n = int(z())
	arr = zzz()
	s = sum(arr)
	for steps in range(n):
		if s % (n - steps) == 0:
			t = s // (n - steps)
			curr = 0
			flag = 1
			for i in range(n):
				curr += arr[i]
				if curr == t:
					curr = 0
				elif curr > t:
					flag = 0
					break
			if flag:
				break
	print(steps)


a = int(input())
import math
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	ans = math.inf
	if z.count(z[0]) == len(z):
		print(0)
		continue
	for j in range(len(z) - 1):
		t = sum(z[0:j + 1])
		total = 0
		r = j + 1
		total = 0
		flag = 0
		size = 0
		fin = j
		while r != len(z):
			total += z[r]
			if total == t:
				total = 0
				r += 1
				flag = 0
				fin += size
				size = 0
				continue
			elif total > t:
				flag = 1
				break
			else:
				size += 1
			r += 1
		if flag == 0 and total == 0:
			ans = min(ans, fin)
	if ans == math.inf:
		print(len(z) - 1)
	else:
		print(ans)


try:
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		total = sum(arr)
		ans = 0
		for i in range(n, 0, -1):
			if total % i == 0:
				need_sum = total // i
				curr_sum = 0
				validator = True
				for j in range(n):
					curr_sum += arr[j]
					if curr_sum > need_sum:
						validator = False
						break
					elif curr_sum == need_sum:
						curr_sum = 0
				if validator:
					ans = n - i
					break
		print(ans)
except e:
	pass


import sys
import math
from heapq import heappop, heappush, heapify

def mati(n):
	return [intl() for i in range(n)]
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : sys.stdout.flush()

def factors(n):
	return set((x for tup in ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0) for x in tup))
for _ in range(iinp()):
	n = iinp()
	a = intl()
	if len(set(a)) == 1:
		print(0)
		continue
	ss = sum(a)
	fac = sorted(list(factors(ss)))
	fl = 1
	for j in fac:
		cur = 0
		for i in a:
			cur += i
			if cur == j:
				cur = 0
			elif cur > j:
				cur = -1
				break
		if cur == 0:
			print(n - ss // j)
			fl = 0
			break
	if fl:
		print(n - 1)


for _ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	b = True
	ans = 0
	sum1 = sum(s)
	for i1 in range(n, 0, -1):
		b = True
		m1 = 0
		if sum1 % i1 == 0:
			for i in range(n):
				m1 += s[i]
				if m1 == sum1 // i1:
					m1 = 0
				elif m1 > sum1 // i1:
					b = False
					break
		if b and sum1 % i1 == 0:
			break
	ans = n - i1
	print(ans)


import bisect
import collections as col
import functools as ft
import heapq
import itertools as it
import math
import os
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def I():
	return int(input().strip())

def S():
	return [x for x in input().strip()]

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

def SL():
	return list(map(str, input().split()))

def ILs(n):
	return list((int(input()) for _ in range(n)))

def SLs(n):
	return list((input().strip() for _ in range(n)))

def ILL(n):
	return [list(map(int, input().split())) for _ in range(n)]

def SLL(n):
	return [list(map(str, input().split())) for _ in range(n)]
MOD = 10 ** 9 + 7
INF = float('inf')

def is_valid(arr, q):
	val = q
	r = 0
	while r < len(arr):
		val -= arr[r]
		if val < 0:
			return False
		elif val == 0:
			if r == len(arr) - 1:
				return True
			val = q
		r += 1
	return False

def main():
	for _ in range(I()):
		n = I()
		a = IL()
		total = sum(a)
		for i in range(n):
			l = n - i
			if total % l == 0:
				q = total // l
				if is_valid(a, q):
					print(i)
					break
main()


from math import ceil, sqrt

def main():
	return '\n'.join(map(str, (nOperationsMinToMerge(*case1462d()) for _ in range(int(input())))))

def case1462d():
	arrayLength = int(input())
	array = tuple(map(int, input().split()))
	return (array, arrayLength)

def nOperationsMinToMerge(array, arrayLength):
	total = sum(array)
	for factor in factorsOf(total):
		(value, success) = (array[0], True)
		for i in range(1, arrayLength):
			if value > factor:
				success = False
				break
			elif value == factor:
				value = array[i]
			else:
				value += array[i]
		if success and value == factor:
			return arrayLength - total // factor

def factorsOf(n):
	yield 1
	if n == 1:
		return
	(factorsStorage, squareRoot_n) = ([n], sqrt(n))
	limit = ceil(squareRoot_n)
	for value in range(2, limit):
		if not n % value:
			yield value
			factorsStorage.append(n // value)
	if squareRoot_n == limit:
		yield limit
	factorsStorage.reverse()
	for factor in factorsStorage:
		yield factor
print(main())


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	s = sum(lst)
	for k in range(n):
		if s % (n - k) == 0:
			x = s // (n - k)
			c = 0
			ind = 0
			su = 0
			while True:
				if ind > n - 1:
					break
				elif su + lst[ind] > x:
					c += 1
					ind = n
					su = 1000000000.0
				elif su + lst[ind] == x:
					su = 0
					ind += 1
				else:
					su += lst[ind]
					ind += 1
			if su == 0:
				print(k)
				break


def neighbour(arr, n):
	total = sum(arr)
	for i in range(n, 0, -1):
		if total % i == 0:
			needed = total // i
			curr = 0
			check = True
			for j in range(n):
				curr += arr[j]
				if curr > needed:
					check = False
					break
				elif curr == needed:
					curr = 0
			if check:
				return n - i
	return n - 1
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(neighbour(arr, n))


for hello in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = sum(a)
	for i in range(n, 0, -1):
		if s % i == 0:
			need_sum = s / i
			cur_sum = 0
			for j in range(0, n):
				cur_sum += a[j]
				ok = True
				if cur_sum > need_sum:
					ok = False
					break
				if cur_sum == need_sum:
					cur_sum = 0
			if ok:
				print(n - i)
				break


def is_valid(arr, k, n, S):
	x = n - k
	if S % x != 0:
		return False
	curr = 0
	val = S / x
	for i in range(n):
		curr += arr[i]
		if curr == val:
			curr = 0
		elif curr > val:
			return False
	return curr == 0

def add_to_neighbour(arr, n):
	S = sum(arr)
	for k in range(n):
		if is_valid(arr, k, n, S):
			print(k)
			return
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	add_to_neighbour(arr, n)
	t -= 1


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

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

def I():
	return int(input())

def S():
	return str(input())
for _ in range(I()):
	n = I()
	a = L()
	s = sum(a)
	for i in range(n, 0, -1):
		if s % i != 0:
			continue
		num = s // i
		sum2 = 0
		fl = True
		for j in range(n):
			sum2 += a[j]
			if sum2 == num:
				sum2 = 0
			elif sum2 > num:
				fl = False
				break
		if fl:
			break
	print(n - i)


import math
from sys import stdin

def get_divisors(n, m):
	res = []
	for k in range(1, int(math.sqrt(n)) + 1):
		if n % k == 0:
			if k >= m:
				res.append(k)
			if n // k >= m:
				res.append(n // k)
	return res
for z in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	s = sum(a)
	m = max(a)
	divisors = sorted(get_divisors(s, m))
	res = -1
	for divisor in divisors:
		cur = 0
		group = 0
		for (idx, val) in enumerate(a):
			cur += val
			if cur == divisor:
				if idx < n - 1:
					cur = 0
				group += 1
			elif cur > divisor:
				break
		if cur == divisor:
			res = n - group
			break
	print(res)


from math import *

def findDivisors(n):
	out = []
	i = 1
	while i * i < n:
		if n % i == 0:
			out.append(i)
		i += 1
	for i in range(int(sqrt(n)), 0, -1):
		if n % i == 0:
			out.append(n // i)
	return out
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(lambda x: int(x), input().split()))
	total = sum(arr)
	list_div = findDivisors(total)
	ans = n - 1
	for div in list_div:
		h = total // div
		t = 0
		i = 0
		flag = True
		steps = 0
		start_i = -1
		while i < n:
			t += arr[i]
			if t == h:
				t = 0
				steps += i - start_i - 1
				start_i = i
			elif t > h:
				flag = False
				break
			i += 1
		if flag:
			ans = min(steps, ans)
	print(ans)


for k in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	t = 0
	for i in range(n):
		t += s[i]
		ans = 0
		for j in range(n):
			ans += s[j]
			if t == ans:
				ans = 0
		if ans == 0:
			print(n - sum(s) // t)
			break
	else:
		print(-1)


inf = 10 ** 5
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = n - 1
	pre = 0
	for i in range(n):
		pre += arr[i]
		m = i
		s = 0
		l = i + 1
		for j in range(i + 1, n):
			s += arr[j]
			if s > pre:
				m += inf
			elif s == pre:
				s = 0
				m += j - l
				l = j + 1
		if s > 0:
			m += inf
		ans = min(ans, m)
	print(ans)


from math import *
import threading
import sys
from collections import defaultdict
from pprint import pprint
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9
inf = 10 ** 15
yes = 'YES'
no = 'NO'
import os
import sys
from io import BytesIO, IOBase
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 npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

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

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

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def dist(a, b):
	d = abs(a[1] - b[1]) + abs(a[2] - b[2])
	return d

def power_of_n(x, n):
	cnt = 0
	while x % n == 0:
		cnt += 1
		x //= n
	return cnt

def factors(n):
	f = []
	for i in range(1, int(sqrt(n)) + 2):
		if n % i == 0:
			f.append(i)
			f.append(n // i)
	f.sort(reverse=True)
	return f
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	fac = factors(s)
	ans = 0
	for i in fac:
		maxrange = s // i
		ans = 0
		cnt = 0
		temp_sum = 0
		f = 1
		for j in range(n):
			cnt += 1
			temp_sum += a[j]
			if temp_sum > maxrange:
				temp_sum = 0
				f = 0
				break
			elif temp_sum == maxrange:
				temp_sum = 0
				ans += cnt - 1
				cnt = 0
		if f == 0:
			continue
		else:
			print(ans)
			break


for y in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	ans = 0
	summ = sum(lst)
	for i in range(n, 0, -1):
		if summ % i == 0:
			cnt = 0
			s = 0
			temp = summ // i
			for j in range(0, n):
				s += lst[j]
				if temp == s:
					cnt += 1
					s = 0
			if cnt == i:
				ans = n - i
				break
	print(ans)


t = int(input())
for q in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = sum(a)
	flag = 0
	min_sample = 0
	for i in list(reversed(range(1, n + 1))):
		v = s / i
		if v % 1 != 0:
			continue
		val = 0
		for (c, j) in enumerate(a):
			val += j
			if c == n - 1 and val == v:
				flag = 1
			if val == v:
				val = 0
			if val > v:
				flag = 0
				break
		if flag == 1:
			min_sample = i
			break
	print(n - min_sample)


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	sums = []
	sums.append(a[0])
	for i in range(1, n):
		sums.append(sums[i - 1] + a[i])
	ans = n - 1
	for i in range(n):
		qu = 0
		divisor = sums[i]
		last_qu = sums[n - 1] / divisor
		if sums[n - 1] % divisor != 0:
			continue
		for idx in range(i, n):
			if sums[idx] / divisor == qu + 1:
				qu += 1
		if qu > 1 and last_qu == qu:
			ans = n - qu
			break
	print(ans)
t = int(input())
while t != 0:
	t -= 1
	solve()


for fghfgf in range(int(input())):
	n = int(input())
	p = [int(i) for i in input().split()]
	s = sum(p)
	ans = len(p) - 1
	for i in range(2, s + 1):
		if s % i == 0:
			now = s // i
			s1 = 0
			for j in range(len(p)):
				s1 += p[j]
				if s1 == now:
					s1 = 0
				elif s1 > now:
					break
			if s1 == 0:
				ans = min(ans, len(p) - i)
	print(ans)


from math import ceil, sqrt, gcd, factorial, comb
from sys import stdin
stdin.readline

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

def it():
	return int(input())

def check(a, x):
	total = 0
	n = len(a)
	s = 0
	j = 0
	for i in range(n):
		s += a[i]
		if s == x:
			total += i - j
			j = i + 1
			s = 0
		elif s > x:
			return -1
	return total

def solve(a, n):
	s = sum(a)
	ans = n - 1
	for i in range(1, int(sqrt(s)) + 1):
		if s % i == 0:
			f1 = i
			f2 = s // i
			a1 = check(a, f1)
			a2 = check(a, f2)
			if a1 != -1:
				ans = min(ans, a1)
			if a2 != -1:
				ans = min(ans, a2)
	return ans
for _ in range(it()):
	n = it()
	l = list(mp())
	print(solve(l, n))


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	s = sum(A)
	for i in range(n):
		if s % (n - i) != 0:
			continue
		p = s // (n - i)
		cur = 0
		flag = True
		for j in range(n):
			if cur + A[j] > p:
				flag = False
				break
			elif cur + A[j] == p:
				cur = 0
			else:
				cur += A[j]
		if flag:
			ans = i
			break
	print(ans)


from math import sqrt

def check(a, x):
	sum = 0
	for item in a:
		if item > x:
			return False
		sum += item
		if sum > x:
			return False
		elif sum == x:
			sum = 0
	return True
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	m = len(a)
	for i in range(1, int(sqrt(s)) + 2):
		if s % i != 0:
			continue
		if check(a, i):
			m = min(m, len(a) - s // i)
		if check(a, s // i):
			m = min(m, len(a) - i)
	print(m)


def check(sm):
	cur = 0
	for i in range(n):
		cur += lis[i]
		if cur == sm:
			cur = 0
		elif cur > sm:
			return False
	return cur == 0
t = int(input())
s = ''
for i in range(t):
	n = int(input())
	lis = [*map(int, input().split())]
	sm = sum(lis)
	ans = -1
	for j in range(n, 0, -1):
		if sm % j == 0 and check(sm // j):
			ans = n - j
			break
	s += f'{ans}\n'
print(s)


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


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	se = set({})
	su = 0
	ans = float('inf')
	br = []
	for i in range(n):
		su += ar[i]
		se.add(su)
		br.append(su)
	for i in se:
		if br[-1] % i == 0:
			flag = True
			for j in range(1, br[-1] // i + 1):
				if not i * j in se:
					flag = False
					break
			if flag:
				req = i
				mem = 0
				ope = 0
				for j in range(n):
					mem += 1
					if br[j] == req:
						ope += mem - 1
						req += i
						mem = 0
				ans = min(ans, ope)
	print(ans)


import sys

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

def maps():
	return [int(i) for i in input().split()]

def func(a, len, x):
	ok = True
	for i in range(n):
		if a[i] != -1:
			j = i + 1
			while j < n and a[i] < x:
				a[i] += a[j]
				a[j] = -1
				j += 1
			if a[i] != x:
				ok = False
				break
		if not ok:
			break
	return (ok, a)
for i in range(*maps()):
	(n,) = maps()
	a = [*maps()]
	s = sum(a)
	if len(set(a)) == 1:
		print(0)
		continue
	se = set()
	for i in range(1, int(s ** 0.5) + 1):
		if s % i == 0:
			se.add(s // i)
			se.add(i)
	ans = 1 << 60
	for N in se:
		(x, y) = func(a[:], N, s // N)
		if x:
			ans = min(ans, sum((1 if i == -1 else 0 for i in y)))
	print(ans)


from itertools import accumulate
from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	sm = 0
	for i in range(n):
		sm += aa[i]
		sm2 = 0
		count = 1
		for j in range(i + 1, n):
			sm2 += aa[j]
			if sm2 > sm:
				break
			elif sm2 == sm:
				count += 1
				sm2 = 0
		if sm2 == 0:
			print(n - count)
			return

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


def KpartitionsPossible(arr, n, K):
	prefix_sum = [0 for i in range(n)]
	prefix_sum[0] = arr[0]
	for i in range(1, n, 1):
		prefix_sum[i] = prefix_sum[i - 1] + arr[i]
	total_sum = prefix_sum[n - 1]
	if total_sum % K != 0:
		return False
	temp = 0
	pos = -1
	for i in range(0, n, 1):
		if pos == -1:
			sub = 0
		else:
			sub = prefix_sum[pos]
		if prefix_sum[i] - sub == total_sum / K:
			pos = i
			temp += 1
		elif prefix_sum[i] - prefix_sum[pos] > total_sum / K:
			break
	return temp == K
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = len(a)
	s = sum(a)
	for i in range(x + 1, 0, -1):
		if s % i == 0:
			if KpartitionsPossible(a, x, i):
				ans = x - i
				break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = n - 1
	s = 0
	for i in range(n - 1):
		s = s + arr[i]
		curr = 0
		r = 1
		for j in range(i + 1, n):
			curr = curr + arr[j]
			if curr == s:
				r = r + 1
				curr = 0
			elif curr > s:
				break
		if curr == 0:
			ans = min(ans, n - r)
	print(ans)


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


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(arr[0]) == len(arr):
		print('0')
	else:
		(sub_arr_sum, ans) = (0, -1)
		for k in range(1, n):
			if sum(arr) % (n - k) == 0:
				(sub_arr_sum_limit, part_cnt, sub_arr_sum) = (sum(arr) // (n - k), 0, 0)
				for i in range(n):
					if sub_arr_sum != sub_arr_sum_limit:
						sub_arr_sum += arr[i]
					else:
						sub_arr_sum = arr[i]
						part_cnt += 1
				if sub_arr_sum == sub_arr_sum_limit:
					part_cnt += 1
				if part_cnt == n - k:
					ans = k
					break
			else:
				continue
			if ans != -1:
				break
		if ans == -1:
			print(n - 1)
		else:
			print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(s, k) = (sum(a), n)
	while k > 0:
		if s % k == 0:
			(cur, need, flag) = (0, s // k, True)
			for i in range(n):
				cur += a[i]
				if cur > need:
					flag = False
					break
				elif cur == need:
					cur = 0
			if flag:
				print(n - k)
				break
		k -= 1


l = input

def answer():
	s = sum(a)
	for opp in range(n, 0, -1):
		if s % opp == 0:
			check = s // opp
		else:
			continue
		b = False
		value = 0
		for val in a:
			value += val
			if value > check:
				b = True
				break
			if value == check:
				value = 0
		if not b:
			return n - opp
for i in range(int(l())):
	n = int(l())
	a = list(map(int, l().split()))
	print(answer())


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	same = all((item == a[0] for item in a))
	if same == True:
		print(0)
	else:
		s = sum(a)
		mx = max(a)
		flag = 1
		ind = 0
		for i in range(n - 1, 0, -1):
			if s % i == 0:
				div = s / i
				if div == s:
					flag = 1
					ind = 1
				elif div >= mx:
					s1 = 0
					for j in range(n):
						if s1 < div:
							s1 += a[j]
						elif s1 == div:
							s1 = a[j]
							flag = 1
							ind = i
						else:
							flag = 0
							s1 = 0
							break
					if s1 == div:
						break
				else:
					pass
			else:
				pass
		if flag:
			print(n - ind)


import sys, collections, math, itertools, random
INF = sys.maxsize

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

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

def input():
	return sys.stdin.readline().strip()
mod = 1000000007

def check(arr, k):
	n = len(arr)
	s = 0
	j = 0
	ans = 0
	for i in range(n):
		s += arr[i]
		if s == k:
			ans += i - j
			j = i + 1
			s = 0
		if s > k:
			return -1
	return ans
for _ in range(int(input())):
	n = int(input())
	arr = get_array()
	ans = n - 1
	s = sum(arr)
	for i in range(1, int(math.sqrt(s)) + 1):
		if s % i == 0:
			f1 = i
			f2 = s // i
			a1 = check(arr, f1)
			a2 = check(arr, f2)
			if a1 != -1:
				ans = min(ans, a1)
			if a2 != -1:
				ans = min(a2, ans)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	for i in range(n, 0, -1):
		if s % i == 0:
			f = True
			needSum = s // i
			cur = 0
			for e in l:
				cur += e
				if cur > needSum:
					f = False
					break
				elif cur == needSum:
					cur = 0
			if f:
				print(n - i)
				break


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor, log
from bisect import bisect_right, bisect_left, bisect
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
LOGN = 30
alp = 'abcdefghijklmnopqrstuvwxyz'
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	for i in range(1, n + 1):
		ss = sum(a[:i])
		cs = 0
		for j in range(n):
			cs += a[j]
			if cs == ss:
				cs = 0
		if cs == 0:
			print(n - sum(a) // ss)
			break


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	total = sum(a)
	for i in range(n):
		k = n - i
		flag = True
		if total % k == 0:
			val = total // k
			ans = 0
			for j in range(n):
				ans += a[j]
				if ans == val:
					ans = 0
				elif ans > val:
					flag = False
					break
			if flag:
				print(i)
				break


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = set()
	s = sum(a)
	for i in range(1, int(math.ceil(math.sqrt(s + 2)))):
		if s % i == 0:
			if s // i == i:
				d.add(i)
			else:
				d.add(i)
				d.add(s // i)
	d = list(d)
	d.sort()
	ans = n - 1
	for i in range(len(d) - 1, -1, -1):
		if d[i] > n:
			continue
		r = s // d[i]
		j = 0
		summ = 0
		flag = True
		while j < len(a):
			if summ < r:
				summ += a[j]
			elif summ > r:
				flag = False
				break
			if summ == r:
				summ = 0
			j += 1
		if flag == True and summ == 0:
			ans = n - d[i]
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	nums = tuple(map(int, input().split()))
	sum_nums = sum(nums)
	for i in range(n, 0, -1):
		nums_2 = list(nums)
		if sum_nums % i == 0:
			cnt = 0
			ave = sum_nums // i
			j = 0
			while j <= len(nums_2) - 2:
				while nums_2[j] < ave:
					nums_2[j] += nums_2[j + 1]
					del nums_2[j + 1]
					cnt += 1
				if nums_2[j] > ave:
					break
				elif nums_2[j] == ave:
					j += 1
			if nums_2 == [ave] * i:
				print(cnt)
				break


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	f = n
	b = [0]
	for x in a:
		b += (x + b[-1],)
	while f:
		if s % f == 0:
			p = s // f
			for i in range(1, f):
				if p * i not in b:
					break
			else:
				ans = 0
				sm = 0
				c = -1
				for x in a:
					sm += x
					c += 1
					if sm == p:
						ans += c
						c = -1
						sm = 0
				print(ans)
				break
		f -= 1


t = int(input())
for q in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = n - 1
	s = sum(arr)
	for k in range(n):
		if s % (n - k):
			continue
		temp = s // (n - k)
		(st, count) = (0, 0)
		for i in range(n):
			st += arr[i]
			if st == temp:
				count += 1
				st = 0
			if st > temp:
				st = 0
				break
		if count == n - k:
			ans = min(ans, k)
	print(ans)


import sys
T = int(input())
for t in range(T):
	ans = 0
	N = int(input())
	ans_ind = 0
	A = list((int(x) for x in input().split()))
	total = int(sum(A))
	for j in range(N):
		if total % (N - j) == 0 and ans == 0:
			div = int(total / (N - j))
			curr_sum = 0
			for left in range(N):
				curr_sum += A[left]
				if curr_sum == div:
					curr_sum = 0
					if left == N - 1:
						ans = 1
						ans_ind = j
				elif curr_sum > div:
					break
	if ans == 1:
		print(ans_ind)
	else:
		print(-1)


T = int(input())
ans_ls = [0] * T
for t in range(T):
	N = int(input())
	a_ls = list(map(int, input().split()))
	csum = [0] * N
	now = 0
	for i in range(N):
		now += a_ls[i]
		csum[i] = now
	ans = float('inf')
	for c in csum:
		now = 0
		i = 0
		can = True
		divs = 0
		for i in range(N):
			now += a_ls[i]
			if now == c:
				now = 0
				divs += 1
			elif now > c:
				can = False
		if not (now == 0 or now == c):
			can = False
		elif now == c:
			divs += 1
		if not can:
			continue
		ans = min(ans, N - divs)
	ans_ls[t] = ans
for ans in ans_ls:
	print(ans)


def solve():
	m = 0
	(n, x) = [int(j) for j in input().split()]
	a = [int(мурк) for мурк in input().split()]
	b = [int(k) for k in input().split()]
	b.reverse()
	for j in range(n):
		if a[j] + b[j] <= x:
			m = m + 1
		else:
			m = -9999999999999999999
	if m > 0:
		print('YES')
	else:
		print('NO')

def cmp(key):
	return key[0]
from math import floor, ceil
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	sum = 0
	naswer = 0
	for j in range(n):
		sum = sum + a[j]
		sum2 = 0
		ans = 1
		fail = False
		for s in range(j + 1, n):
			sum2 = sum2 + a[s]
			if sum2 > sum:
				fail = True
				break
			if sum2 == sum:
				ans = ans + 1
				sum2 = 0
		if fail == False and sum2 == 0:
			naswer = max(naswer, ans)
	print(n - naswer)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	x = sum(A)
	for i in range(n):
		z = True
		if x % (n - i) == 0:
			t = x // (n - i)
			w = 0
			for j in range(len(A)):
				if A[j] + w > t:
					z = False
					break
				w += A[j]
				w %= t
			if z:
				print(i)
				break
		else:
			z = False


def testcase():
	n = int(input())
	arr = list(map(int, input().split()))
	best = n - 1
	ssf = 0
	for i in range(n - 1):
		ssf += arr[i]
		curr_ssf = 0
		curr_n = 1
		flag = True
		for j in range(i + 1, n):
			curr_ssf += arr[j]
			if curr_ssf == ssf:
				curr_ssf = 0
				curr_n += 1
			elif curr_ssf > ssf:
				flag = False
				break
		if curr_ssf == ssf:
			curr_n += 1
		elif curr_ssf != 0:
			flag = False
		if flag:
			best = min(best, n - curr_n)
	print(best)
	return
import sys, os
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
sys.setrecursionlimit(10 ** 5)
t = int(input())
for _ in range(t):
	testcase()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

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

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

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def function(arr, size, dp):
	if size == 1 or size == 0:
		return 1
	key = ''.join(map(str, arr[:size]))
	if dp[key]:
		return dp[key]
	output = function(arr, size - 1, dp)
	key = ''.join(map(str, arr[:size - 1]))
	dp[key] = output
	if arr[size - 2] * 10 + arr[size - 1] <= 26:
		output += function(arr, size - 2, dp)
		key = ''.join(map(str, arr[:size - 2]))
		dp[key] = output
	return output

def main():
	for _ in range(ii()):
		n = ii()
		b = li()
		s = sum(b)
		for k in range(n):
			ss = s / (n - k)
			j = 0
			m = 0
			arr = b[:]
			while j < n:
				if arr[j] < ss:
					if j + 1 < n and arr[j] + arr[j + 1] < ss:
						arr[j + 1] += arr[j]
						m += 1
					elif j + 1 < n and arr[j] + arr[j + 1] == ss:
						arr[j + 1] += arr[j]
						m += 1
						j += 1
					else:
						break
				elif arr[j] == ss:
					j += 1
					continue
				else:
					break
				j += 1
			else:
				break
		print(k)
main()


t = int(input())
INF = 1 << 60

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = INF
	s = 0
	for i in range(n):
		s += a[i]
		cnt = 0
		tmpsum = 0
		for j in range(n):
			if tmpsum < s:
				tmpsum += a[j]
				continue
			elif tmpsum == s:
				cnt += 1
				tmpsum = a[j]
				continue
			else:
				cnt = -INF
				break
		if tmpsum == s:
			cnt += 1
		else:
			cnt = -INF
		ans = min(ans, n - cnt)
	print(ans)
for i in range(t):
	solve()


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	(*a,) = R()
	for i in range(1, n):
		a[i] += a[i - 1]
	for i in range(n):
		if a[-1] % a[i] == 0:
			p = 0
			for j in range(i, n):
				if a[j] % a[i] == 0:
					p += 1
			if a[-1] // a[i] == p:
				ans = n - p
				break
	print(ans)


from math import *
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mx = max(a)
	sum = 0
	check1 = 0
	cnt = 0
	for i in range(n):
		sum += a[i]
	for i in range(n):
		x = n - i
		if sum % x == 0:
			check = 0
			cnt = sum / x
			sum1 = 0
			for j in range(n):
				sum1 += a[j]
				if sum1 == cnt:
					sum1 = 0
				if sum1 > cnt:
					check = 1
					break
			if check == 0:
				check1 = 1
				print(i)
				break
		if check1 == 1:
			break


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l)
	for i in range(n, 0, -1):
		if s % i == 0:
			ns = s // i
			s1 = 0
			f = 1
			for j in range(n):
				s1 += l[j]
				if s1 > ns:
					f = 0
					break
				elif s1 == ns:
					f = 1
					s1 = 0
			if f == 1:
				print(n - i)
				break


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	sumy = sum(l)
	maxy = max(l)
	if maxy > sumy // 2:
		print(n - 1)
	else:
		count = n - 1
		for i in range(n, 0, -1):
			if sumy % i == 0:
				shan = sumy // i
				siri = 0
				i = 0
				ele = 0
				mps = 0
				while i < n:
					ele += l[i]
					if ele > shan:
						siri = 1
						break
					if ele < shan:
						mps += 1
					if ele == shan:
						ele = 0
					i += 1
				if siri == 0:
					count = min(mps, count)
		print(count)


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
import math
INT_MAX = 10 ** 13
from bisect import bisect_left
import sys
MOD = 998244353
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	ans = n - 1
	s = sum(A)

	def pos(each):
		reality = 0
		presentsum = 0
		count = 0
		for i in range(n):
			presentsum += A[i]
			if presentsum > each:
				return INT_MAX
			elif presentsum == each:
				reality += count
				presentsum = 0
				count = 0
			else:
				count += 1
		if (presentsum < each or presentsum > each) and presentsum > 0:
			return INT_MAX
		else:
			return reality + count
	i = 1
	while i ** 2 <= s:
		if s % i == 0:
			each = i
			nfb = s // i
			ans = min(ans, pos(each), pos(s // each))
		i += 1
	print(ans)
	print()


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	for k in range(n):
		if s % (n - k) == 0:
			s1 = s // (n - k)
			(i, s11, flag) = (0, 0, 0)
			while i < n:
				if s11 == s1:
					s11 = 0
				if s11 + arr[i] <= s1:
					s11 += arr[i]
				else:
					flag = 1
					break
				i += 1
			if s11 == s1 and flag == 0:
				break
	print(k)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sum_ = sum(a)
	for j in range(n):
		if sum_ % (n - j) == 0:
			elem = sum_ // (n - j)
			i = 1
			curr = a[0]
			co = 0
			while i < n:
				if curr < elem:
					curr += a[i]
					co += 1
					i += 1
				elif curr == elem:
					curr = a[i]
					i += 1
				else:
					break
			if co == j and curr == elem:
				print(j)
				break


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	for i in range(1, n + 1):
		s = sum(a[:i])
		c = 0
		for j in range(n):
			c += a[j]
			if c == s:
				c = 0
		if c == 0:
			print(n - sum(a) // s)
			return
n = int(input())
for i in range(n):
	solve()


import math, sys
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

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

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		ans = 0
		for i in range(n):
			pre = 0
			cnt = 0
			for k in range(i + 1):
				pre += l[k]
			I1 = pre
			cnt += 1
			pre = 0
			for j in range(i + 1, n):
				pre += l[j]
				if pre == I1:
					pre = 0
					cnt += 1
			if pre == 0:
				ans = max(ans, cnt)
			else:
				continue
		print(n - ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


def possible(r, pa, n):
	s = pa[-1]
	if s % (n - r) != 0:
		return False
	step = s // (n - r)
	nbi = n - r
	marque = [False] * (1 + nbi)
	lum = 0
	for x in pa:
		if x % step == 0:
			if not marque[x // step]:
				marque[x // step] = True
				lum += 1
	if lum == 1 + nbi:
		return True
	else:
		return False

def rep(n, pa):
	for r in range(n):
		if possible(r, pa, n):
			return r
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	pa = [0]
	s = 0
	for x in a:
		s += x
		pa.append(s)
	print(rep(n, pa))


import math

def answer_check(x, lst):
	x1 = 0
	for j in lst:
		x1 += j
		if x1 == x:
			x1 = 0
			continue
		elif x1 < x:
			continue
		else:
			return False
	return True
t = int(input())
for z in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	ma = max(lst)
	su = sum(lst)
	ma_cnt = len(lst) - 1
	for i in range(1, int(math.sqrt(su)) + 2):
		if su % i == 0:
			b = answer_check(i, lst)
			if b is True:
				if ma_cnt > n - su // i:
					ma_cnt = n - su // i
			b = answer_check(su // i, lst)
			if b is True:
				if ma_cnt > n - i:
					ma_cnt = n - i
	print(ma_cnt)


def attempt(n, a, start, su):
	swaps = 0
	z = start
	curr = 0
	while z < n:
		if curr + a[z] > su:
			return -1
		elif curr + a[z] == su:
			if curr != 0:
				swaps += 1
			curr = 0
		else:
			if curr != 0:
				swaps += 1
			curr += a[z]
		z += 1
	if curr:
		return -1
	return swaps

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		pref = 0
		best = n
		for i in range(n):
			pref += a[i]
			swaps = attempt(n, a, i + 1, pref)
			if swaps == -1:
				continue
			best = min(best, swaps + i)
		print(best)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(0)
		continue
	else:
		s = sum(a)
		for j in range(n - 1, 0, -1):
			if s % j == 0:
				t = 0
				c = n - j
				y = s // j
				for i in range(n):
					if c <= 0:
						break
					if t == y:
						t = 0
						continue
					if t < y:
						if t == 0:
							t += a[i]
						else:
							t += a[i]
							c -= 1
						if t > y:
							break
						if t == y:
							c += 1
							t = 0
				if t == 0:
					print(n - j)
					break


import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	f = []
	b = []
	for i in range(1, math.floor(math.sqrt(s)) + 1):
		k = s // i
		if k * i == s:
			if k == i:
				f.append(i)
			else:
				f.append(i)
				b.append(k)
	fn = f + b[::-1]
	p = 0
	for i in fn:
		sm = 0
		t = 0
		for j in a:
			sm += j
			if sm == i:
				sm = 0
			elif sm > i:
				t = 1
				break
		if t == 0:
			p = 1
			break
	print(n - s // i)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	s = sum(a)
	ans = 0
	while ans < n - 1:
		if not s % (n - ans):
			ss = s // (n - ans)
			k = 0
			for i in a:
				k += i
				if k > ss:
					break
				elif k == ss:
					k = 0
			else:
				if not k:
					print(ans)
					break
		ans += 1
	else:
		print(n - 1)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print(0)
		continue
	s = sum(arr)
	answer = -1
	for k in range(1, n):
		if s % (n - k) == 0:
			summ = 0
			for i in range(n):
				summ += arr[i]
				if i == n - 1:
					if summ != s / (n - k):
						continue
					else:
						answer = k
						break
				if summ == s / (n - k):
					summ = 0
				elif summ > s / (n - k):
					break
		if answer > -1:
			break
	print(answer)


t = int(input())
for z in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	mn = max(arr)
	if len(set(arr)) == 1:
		print(0)
	else:
		for i in range(n - 1, 0, -1):
			if s % i == 0 and s // i >= mn:
				j = 0
				while j < n:
					if arr[j] == s // i:
						j = j + 1
					elif arr[j] < s // i:
						count = arr[j]
						while count < s // i and j < n:
							j = j + 1
							if arr[j] == s // i:
								break
							else:
								count = count + arr[j]
						if count == s // i:
							j = j + 1
						else:
							break
				if j == n:
					break
		print(n - i)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += l[i]
		ans = 0
		for j in range(n):
			ans += l[j]
			if ans == s:
				ans = 0
		if ans == 0:
			print(n - sum(l) // s)
			break
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sm = sum(a)
	check = False
	for i in range(n, 0, -1):
		if sm % i == 0:
			cnt = 0
			b = []
			for j in a:
				b.append(j)
			check = False
			for j in range(n - 1):
				if cnt == n - i:
					for k in range(j + 1, n):
						if b[k] != sm // i:
							check = True
							break
					break
				if b[j] > sm // i:
					check = True
					break
				if b[j] < sm // i:
					b[j + 1] += b[j]
					cnt += 1
			if not check and b[-1] == sm // i:
				print(n - i)
				break


for l in [*open(0)][2::2]:
	n = s = 0
	t = {0}
	for x in l.split():
		s += int(x)
		t |= {s}
		n = k = n + 1
	while s % k or {*range(0, s, s // k)} - t:
		k -= 1
	print(n - k)


t = int(input())
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = -1
	total = 0
	for i in range(n):
		total += l[i]
		c = 0
		d = 0
		m = 0
		for j in range(n):
			c += l[j]
			d += 1
			if c == total:
				c = 0
				m += d - 1
				d = 0
		if c == total:
			c = 0
			m += d - 1
			d = 0
		if c == 0:
			if ans == -1:
				ans = m
			else:
				ans = min(ans, m)
	print(ans)


def solution():
	for tc in range(int(input())):
		n = int(input())
		ls = list(map(int, input().split()))
		tot_sum = sum(ls)
		for k in range(n):
			if tot_sum % (n - k) != 0:
				continue
			cur_tgt = tot_sum // (n - k)
			cur_sum = 0
			for idx in range(len(ls)):
				cur_sum += ls[idx]
				if cur_sum > cur_tgt:
					break
				elif cur_sum == cur_tgt:
					cur_sum = 0
			if cur_sum == 0:
				break
		print(k)
solution()


import sys, os, getpass
import heapq as hq
import math, random, functools, itertools
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
from functools import reduce

def all_divisors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve_(arr):
	sumarr = sum(arr)
	divs = all_divisors(sumarr)
	minres = len(arr) - 1
	for div in divs:
		if sumarr % div != 0:
			continue
		segment = sumarr // div
		cur = 0
		for a in arr:
			cur += a
			if cur > segment:
				break
			if cur == segment:
				cur = 0
		else:
			minres = min(minres, len(arr) - div)
	return minres

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]
for case_num in range(int(input())):
	k = int(input())
	lst = list(map(int, input().split()))
	res = solve(lst)
	print(res)


for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	pref = [0]
	for i in range(n):
		pref.append(pref[-1] + a[i])
	prefset = set()
	for i in range(n + 1):
		prefset.add(pref[i])
	for i in range(1, n + 1):
		if not pref[-1] % pref[i] == 0:
			continue
		fl = 1
		for j in range(round(pref[-1] / pref[i])):
			if not j * pref[i] in prefset:
				fl = 0
		if fl:
			print(n - round(pref[-1] / pref[i]))
			break


import sys
input = sys.stdin.readline
import math
import copy
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	total = sum(arr)
	ans = -1
	for i in range(n):
		if total % (n - i) != 0:
			continue
		target = total // (n - i)
		current = 0
		index = 0
		count = 0
		possible = True
		while index < n:
			if current != 0:
				count += 1
			current += arr[index]
			if current > target:
				possible = False
			if current == target:
				current = 0
			index += 1
		if count > i:
			possible = False
		if possible:
			ans = i
			break
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	for i in range(n, 0, -1):
		if s % i == 0:
			cursum = s // i
			cur = 0
			ok = True
			for j in range(n):
				cur += arr[j]
				if cur > cursum:
					ok = False
					break
				elif cur == cursum:
					cur = 0
			if ok:
				print(n - i)
				break
	if not ok:
		print(n - 1)


import sys
import math, bisect, operator
(inf, m) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = I()
	a = Neo()
	t = sum(a)
	for i in range(n):
		if t % (n - i) != 0:
			continue
		else:
			z = t / (n - i)
			x = 0
			for j in range(n):
				if x + a[j] < z:
					x = x + a[j]
				elif x + a[j] == z:
					x = x + a[j]
					x = 0
				elif x + a[j] > z:
					x += a[j]
					break
			if x == 0:
				print(i)
				break


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = sum(a)
	cnt = 1
	m = 0
	while m < s:
		m = sum(a[:cnt])
		temp = 0
		if s % m == 0:
			curr = 0
			for i in range(n):
				if curr < m:
					curr += a[i]
				if curr == m:
					curr = 0
				if curr > m:
					temp = 1
					break
			if curr != 0:
				temp = 1
			if temp == 0:
				break
		cnt += 1
	print(n - round(s / m))


t = int(input())
for p in range(t):
	n = int(input())
	a = input().split()
	sumArray = 0
	ops = []
	for i in range(n):
		a[i] = int(a[i])
		sumArray += a[i]
	for i in range(1, n + 1):
		if sumArray % i == 0:
			eachValue = sumArray // i
			start = 0
			valid = True
			while start < n and valid:
				sumgroup = 0
				for end in range(start, n):
					sumgroup += a[end]
					if sumgroup == eachValue:
						start = end + 1
						break
					elif sumgroup > eachValue:
						valid = False
						break
			if valid:
				ops.append(n - i)
	print(min(ops))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	s = sum(a)
	for k in range(s):
		if s % (n - k) == 0:
			ps = s // (n - k)
			tmpSum = 0
			for i in a:
				if tmpSum > ps:
					break
				elif tmpSum < ps:
					tmpSum += i
				else:
					tmpSum = i
			if tmpSum == ps:
				print(k)
				break


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ss = 0
	b = []
	k = sum(a)
	for i in range(n):
		ss += a[i]
		cnt = 0
		flag = 0
		if k % ss == 0:
			for j in range(i + 1, n):
				cnt += a[j]
				if cnt > ss:
					flag = 1
					break
				elif cnt == ss:
					cnt = 0
			if flag == 0:
				b.append(n - k // ss)
	if len(b):
		print(min(b))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	m = sum(a)
	for i in range(n, 0, -1):
		if m % i == 0:
			b.append(m // i)
	for i in b:
		x = 0
		f = 0
		for j in range(n):
			x += a[j]
			if x == i:
				x = 0
			elif x > i:
				x = 0
				f = 1
				break
		if x:
			if x > i:
				f = 1
		if f == 0:
			break
	print(n - m // i)


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

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

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

def invr():
	return map(int, input().split())
f = []

def fact(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncr(n, r, m):
	if r == 0:
		return 1
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def main():
	D()

def A():
	t = pi()
	while t:
		t -= 1
		n = pi()
		a = ti()
		res = []
		(p1, p2) = (0, n - 1)
		while p1 <= p2:
			res.append(a[p1])
			if p1 != p2:
				res.append(a[p2])
			p1 += 1
			p2 -= 1
		print(*res, sep=' ')

def B():
	t = pi()
	while t:
		t -= 1
		n = pi()
		s = ts()
		f = 0
		for i in range(n):
			if s[i] == '2':
				for j in range(i + 1, n):
					if j < n and j + 1 < n and (j + 2 < n) and (s[j] + s[j + 1] + s[j + 2] == '020'):
						if j - i == 1:
							if i == 0:
								f = 1
							if j + 2 == n - 1:
								f = 1
						elif i == 0 and j + 2 == n - 1:
							f = 1
		if f == 0:
			for i in range(n):
				if i + 1 < n and s[i] + s[i + 1] == '20':
					for j in range(i + 2, n):
						if j + 1 < n and s[j] + s[j + 1] == '20':
							if j - i - 1 == 1:
								if i == 0:
									f = 1
								if j + 1 == n - 1:
									f = 1
							elif i == 0 and j + 1 == n - 1:
								f = 1
		if f == 0:
			for i in range(n):
				if i + 1 < n and i + 2 < n and (s[i] + s[i + 1] + s[i + 2] == '202'):
					for j in range(i + 3, n):
						if s[j] == '0':
							if j - i - 2 == 1:
								if i == 0 or j == n - 1:
									f = 1
							elif i == 0 and j == n - 1:
								f = 1
		if f:
			print('YES')
		else:
			print('NO')

def C():
	t = pi()
	while t:
		t -= 1
		x = pi()
		if x < 10:
			print(x)
			continue
		mn = 9999999999999999999999999
		f = 0
		res = '-1'
		for i in range(x):
			if f == 1:
				res = num[::-1]
				break
			temp = x
			num = ''
			mp = [0 for i in range(10)]
			for j in range(i):
				for k in range(9, -1, -1):
					if mp[k]:
						continue
					if temp - k < 0:
						continue
					num += str(k)
					temp -= k
					mp[k] = 1
					break
			if temp == 0:
				f = 1
		print(res)

def getFactors(n):
	i = 1
	f = []
	while i * i <= n:
		if n % i == 0:
			f.append(int(i))
			f.append(int(n / i))
		i += 1
	return f

def D():
	t = pi()
	while t:
		t -= 1
		n = pi()
		a = ti()
		sum = 0
		for i in range(n):
			sum += a[i]
		factors = getFactors(sum)
		factors = sorted(factors)
		mp = {}
		s = 0
		for i in range(n):
			s += a[i]
			mp[str(s)] = 1
		mn = 99999999999999999
		res = 1
		steps = 0
		for i in range(len(factors)):
			j = 1
			f = 1
			while j * factors[i] <= sum:
				key = j * factors[i]
				if not str(key) in mp:
					f = 0
					break
				j += 1
			if f and sum % factors[i] == 0:
				res = factors[i]
				break
		prefixSum = [0 for i in range(n)]
		prefixSum[0] = a[0]
		for i in range(1, n):
			prefixSum[i] = a[i] + prefixSum[i - 1]
		pre = 0
		for i in range(n):
			if prefixSum[i] % res == 0:
				steps += i - pre
				pre = i + 1
		print(steps)
main()


def do():
	n = int(input())
	dat = list(map(int, input().split()))
	initval = 0
	end = False
	for iii in range(n):
		if end:
			break
		if iii == n - 1:
			print(n - 1)
			end = True
		if end:
			break
		initval += dat[iii]
		cur = 0
		can = True
		for i in range(iii + 1, n):
			cur += dat[i]
			if cur == initval:
				cur = 0
				continue
			if cur > initval:
				can = False
				break
		if cur != 0:
			can = False
		if can is True:
			target = initval
			res = 0
			i = 0
			cur = 0
			cnt = 0
			for i in range(n):
				cur += dat[i]
				cnt += 1
				if cur == target:
					res += cnt - 1
					cur = 0
					cnt = 0
					continue
			print(res)
			return
		if end:
			break
q = int(input())
for _ in range(q):
	do()


for case in range(1, int(input()) + 1):
	val = 0
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = sum(arr)
	for k in range(n):
		each_value = s / (n - k)
		for i in range(n):
			val += arr[i]
			if val > each_value:
				val = 0
				flag = False
				break
			elif val == each_value:
				val = 0
				flag = True
				ans = k
		if flag == True:
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	sm = sum(arr)
	for j in range(n):
		if sm % (n - j) == 0:
			t = sm // (n - j)
			x = 0
			for i in range(n - 1, -1, -1):
				x += arr[i]
				if x == t:
					x = 0
					if i == 0:
						print(j)
						x = -2
						break
				if x > t:
					break
			if x == -2:
				break


for _ in range(int(input())):
	size = int(input())
	gl = list(map(int, input().split()))
	gsum = sum(gl)
	for i in range(size, 0, -1):
		if gsum % i == 0:
			needsum = gsum / i
			cursum = 0
			flag = True
			for j in range(size):
				cursum += gl[j]
				if cursum > needsum:
					flag = False
					break
				elif cursum == needsum:
					cursum = 0
			if flag:
				print(size - i)
				break


from sys import stdin
input = stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = sum(arr)
	ans = n
	while ans >= 1:
		if s % ans != 0:
			ans = ans - 1
			continue
		x = s // ans
		i = 0
		flag = False
		while i < n:
			pre = 0
			j = i
			while j < n:
				if pre + arr[j] > x:
					flag = True
					break
				elif pre + arr[j] < x:
					pre = pre + arr[j]
					j = j + 1
				elif pre + arr[j] == x:
					i = j + 1
					break
			if flag == True:
				break
		if flag == False:
			print(n - ans)
			break
		else:
			ans = ans - 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += a[i]
		c = 0
		for j in range(n):
			c += a[j]
			if c == s:
				c = 0
		if c == 0:
			print(n - sum(a) // s)
			break
	else:
		print(-1)


t = int(input())
for dummy in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = sum(arr)
	l = len(arr)
	mk = 1
	found_soluton = False
	for ku in range(0, l):
		k = l - ku
		if s % k == 0:
			counter = 0
			tr = 0
			sumperpart = s // k
			end = 0
			position = 0
			sum_of_elements = 0
			old_array = arr
			new_array = []
			stop_flag = False
			if not found_soluton:
				while sum_of_elements < sumperpart and (not stop_flag) and (position < len(arr)):
					sum_of_elements += arr[position]
					if sum_of_elements == sumperpart:
						new_array.append(sum_of_elements)
						sum_of_elements = 0
					position += 1
					if sum_of_elements > sumperpart:
						stop_flag = True
					if len(new_array) == k:
						found_soluton = True
						print(len(arr) - len(new_array))


test = int(input())
for t in range(0, test):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	ans = n
	for i in range(0, n):
		s = sum(a[:i + 1])
		j = i + 1
		t = 0
		p = [i]
		while j < n:
			t += a[j]
			if t == s:
				t = 0
				p.append(j)
			elif t > s:
				break
			j += 1
		if t == 0:
			ans = min(ans, n - len(p))
	print(ans)


import math

def divisors(n):
	i = 2
	l = []
	while i <= math.floor(math.sqrt(n)):
		if n % i == 0:
			l.append(i)
			l.append(n // i)
		i += 1
	return l
for w in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	x = -1
	prefix = [0] * n
	prefix[0] = a[0]
	for i in range(1, n):
		prefix[i] = prefix[i - 1] + a[i]
	if len(set(a)) == 1:
		print(0)
	else:
		l = divisors(s)
		if l == []:
			print(n - 1)
		else:
			for j in range(len(l)):
				i = 0
				count = 0
				ptr = -1
				while i < n:
					if ptr == -1:
						if prefix[i] == l[j]:
							ptr = i
							count += 1
					elif prefix[i] - prefix[ptr] == l[j]:
						ptr = i
						count += 1
					i += 1
				if count == s // l[j]:
					x = max(x, s // l[j])
			if x != -1:
				print(n - x)
			else:
				print(n - 1)


def solve(a, pos):
	if pos == len(a) - 1:
		return len(a)
	if a[pos] == a[pos + 1]:
		return solve(a, pos + 1)
	if len(a) - pos == 2 or a[pos] < a[pos + 1] + a[pos + 2]:
		return solve([a[0] + a[1]] + a[2:], 0)
	elif pos == 0:
		return max(solve([a[0] + a[1]] + a[2:], 0), solve([a[pos], a[pos + 1] + a[pos + 2]] + a[3:], 0))
	else:
		return max(solve([a[0] + a[1]] + a[2:], 0), solve(a[:pos + 1] + [a[pos + 1] + a[pos + 2]] + a[pos + 3:], pos - 1))
for test in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	summ = sum(ar)
	for k in range(n):
		if not summ % (n - k) == 0:
			continue
		target = summ // (n - k)
		acc = 0
		ok = True
		for el in ar:
			acc += el
			if acc > target:
				ok = False
				break
			if acc == target:
				acc = 0
		if ok:
			print(k)
			break


import sys
input = sys.stdin.readline
from functools import reduce
from itertools import accumulate

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	sa = sum(a)
	Ma = max(a)
	fac = sorted([i for i in factors(sa) if i >= Ma])
	psa = set([*accumulate(a)])
	for f in fac:
		ans = True
		for g in range(1, sa // f + 1):
			if f * g not in psa:
				ans = False
				break
		if ans:
			print(n - sa // f)
			break


import sys
import math
t = input()
for i in range(int(t)):
	x = input()
	n = [int(x) for x in input().split()]
	x = int(x)
	sum = 0
	for j in range(len(n)):
		sum += n[j]
	for j in range(x, 0, -1):
		div = 0
		if sum % j == 0:
			div = sum // j
			partsum = 0
			flag = True
			for k in range(len(n)):
				partsum += n[k]
				if partsum == div:
					partsum = 0
				elif partsum > div:
					flag = False
					break
			if flag:
				break
	ans = x - sum // div
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
start_time = time.time()

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 998244353

def solve():
	N = getInt()
	A = getInts()
	left = 0
	right = N - 1
	S = sum(A)

	def works(x):
		blocks = N - x
		if S % blocks > 0:
			return False
		targ = S // blocks
		curr = 0
		count = 0
		for a in A:
			curr += a
			if curr > targ:
				return False
			if curr == targ:
				curr = 0
				count += 1
		return count == blocks and curr == 0
	i = 0
	while True:
		if works(i):
			return i
		i += 1
for _ in range(getInt()):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	s = sum(a)
	for i in range(n, 0, -1):
		if s % i == 0:
			(q, p, ok) = (0, s // i, True)
			for j in range(n):
				q += a[j]
				if q > p:
					ok = False
					break
				elif q == p:
					q = 0
			if ok:
				print(n - i)
				break


import math
t = int(input())

def solve():
	n = int(input())
	nums = list(map(int, input().split()))
	sum_n = sum(nums)
	sumtill = [0] * n
	sumtill[0] = nums[0]
	for it in range(1, n):
		sumtill[it] = sumtill[it - 1] + nums[it]
	finalCount = n - 1
	for it in range(n - 1):
		count = 0
		if sum_n % sumtill[it] == 0:
			count += it
			sum_temp = 0
			taken = 0
			last = it + 1
			for it2 in range(it + 1, n):
				sum_temp += nums[it2]
				if sum_temp > sumtill[it]:
					break
				if sum_temp == sumtill[it]:
					taken += 1
					sum_temp = 0
					count += it2 - last
					last = it2 + 1
			if taken == sum_n / sumtill[it] - 1:
				finalCount = min(finalCount, count)
	return finalCount
for i in range(t):
	output = solve()
	print(output)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ps = 0
	ans = n - 1
	for i in range(0, n):
		c = 1
		s = 0
		f = 1
		ps = ps + a[i]
		for j in range(i + 1, n):
			s = s + a[j]
			if s == ps:
				c = c + 1
				s = 0
			elif s > ps or j == n - 1:
				f = 0
				break
		if f == 1:
			ans = min(ans, n - c)
	print(ans)


t = int(input())
for i in range(0, t):
	n = input()
	li = [int(x) for x in input().split(' ')]
	total_sum = sum(li)
	possibi = []
	cru = 0
	for i in range(0, len(li)):
		cru += li[i]
		if total_sum % cru == 0:
			possibi.append(cru)
	for su in possibi:
		poi = 0
		csu = 0
		while poi < len(li):
			csu += li[poi]
			if csu > su:
				break
			elif csu == su:
				csu = 0
				poi += 1
			elif csu < su:
				poi += 1
		if poi == len(li):
			cou = int(total_sum / su)
			print(len(li) - cou)
			break


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	total = sum(arr)
	for i in range(n, 0, -1):
		if total % i == 0:
			sumBalance = total // i
			sumCurr = 0
			flag = True
			for j in range(n):
				sumCurr += arr[j]
				if sumCurr > sumBalance:
					flag = False
					break
				elif sumCurr == sumBalance:
					sumCurr = 0
			if flag == True:
				print(n - i)
				return
t = int(input())
for _ in range(t):
	solve()


import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def isequal(arr):
	if len(set(arr)) == 1:
		return True
	return False

def solve():
	n = iinp()
	arr = intl()
	arr.insert(0, 0)
	arr.append(0)
	sum = 0
	for i in range(1, n + 1):
		sum += arr[i]
	ans = 0
	for i in range(0, n):
		if sum % (n - i) != 0:
			continue
		elem = sum // (n - i)
		rem = 0
		brr = arr.copy()
		flag = True
		for j in range(1, n + 1):
			if brr[j] == elem:
				continue
			elif brr[j] > elem:
				flag = False
			elif brr[j] < elem:
				rem += 1
				brr[j + 1] += brr[j]
		flag &= i == rem
		if flag:
			print(i)
			return
start_time = time.time()
for _ in range(iinp()):
	solve()


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	ans = []
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		d = set()
		s = arr[0]
		same = 1
		d.add(s)
		for i in range(1, n):
			s += arr[i]
			arr[i] += arr[i - 1]
			d.add(arr[i])
			same &= arr[i] == arr[i - 1]
		if same:
			ans.append(0)
			continue
		fl = 0
		for i in arr:
			t = i
			while t <= s:
				if not t in d:
					break
				t += i
				if t == s:
					fl = 1
					break
			if fl:
				break
		ans.append(n - s // i)
	print('\n'.join(map(str, ans)))
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = 1
	s = 0
	for i in range(n):
		s += a[i]
		t = 1
		cs = 0
		for j in range(i + 1, n):
			cs += a[j]
			if cs == s:
				cs = 0
				t += 1
			elif cs > s:
				break
		else:
			if cs != 0:
				continue
			maxi = max(maxi, t)
	print(n - maxi)


from sys import exit, stderr, stdout
from math import sqrt

def debug(*args):
	for i in args:
		stderr.write(str(i) + ' ')
	stderr.write('\n')

class Input:

	def __init__(self):
		self.sum = 0
		self.mx = 0

	def inp(self, x):
		self.sum += x
		self.mx = max(self.mx, x)
		return x

def factors(N):
	lim = N // 2 + 1
	ret = []
	for i in range(obj.mx, lim):
		if N % i == 0:
			ret.append(i)
	return ret
for _ in range(int(input())):
	n = int(input())
	obj = Input()
	a = [obj.inp(int(x)) for x in input().split()]
	divisors = factors(obj.sum)
	D = len(divisors)
	if n == 1:
		print(0)
		continue
	if D == 0:
		print(n - 1)
		continue
	(j, tmp, fg) = (0, 0, False)
	for i in range(n):
		tmp += a[i]
		while tmp > divisors[j]:
			if j + 1 < D:
				if tmp < divisors[j + 1]:
					break
				j += 1
			else:
				break
		if tmp in divisors[j:]:
			(tp, k) = (0, i + 1)
			ans = 0
			if i > 0:
				ans = i
			while True:
				if k >= n:
					fg = True
					break
				tp += a[k]
				if a[k] != tmp:
					ans += 1
				if tp == tmp:
					tp = 0
					if ans > 0 and a[k] != tmp:
						ans -= 1
				elif tp > tmp:
					break
				k += 1
			if fg:
				break
	if fg:
		print(ans)
	else:
		print(n - 1)