# Why do I get SIGFPE in my code

#include<bits/stdc++.h>
using namespace std;

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl ‘\n’
#define ll long long

#define f(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()

ll gcd(ll a,ll b)
{
ll M=(a>b)?a:b;
ll m=(a<b)?a:b;
if(a%b==0)
{
return b;
}
else
{
return gcd(b,a%b);
}
}

bool is_prime(ll n)
{
if(n==1)
{
return false;
}
else if(n==2|n==3)
{
return true;
}
else
{
for(ll i=2;i<=sqrt(n);i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
}

vector div_arr(ll n)
{
vector arr;
for(ll i=1;i<=sqrt(n);i++)
{
if(n%i==0)
{
arr.push_back(n/i);
arr.push_back(i);
}
}
if(floor(sqrt(n))==sqrt(n))
{
arr.pop_back();
}
sort(all(arr));
return arr;
}

int main()
{
FASTIO;
ll T;
cin>>T;
while(T–)
{
ll N;
cin>>N;
vector arr(N);
vector temp(N);
f(i,N)
{
cin>>arr[i];
temp[i]=arr[i];
}
ll sum=accumulate(all(arr),0);
if(sum!=0)
{
sum=abs(sum);
ll arr_index=0,div_index=0,div_final=-1,temp_sum=0,change=0;
vector div=div_arr(sum);
f(i,div.size())
{
if((N-(sum/div[i]))>=0)
{
div_index=i;
break;
}
}
while(div_final==-1)
{
temp=arr;
arr_index=0;
change=0;
temp_sum=0;
for(ll i=arr_index;i<N;i++)
{
temp_sum+=temp[i];
temp[arr_index]=temp_sum;
if((temp[arr_index]==div[div_index])&&(i+1<N)&&(temp[i+1]!=0))
{
temp_sum=0;
arr_index=i+1;
change++;
}
if((i==N-1)&&(div_final==-1)&&(change+1==sum/div[div_index]))
{
div_final=div[div_index];
}
}
div_index++;
}
cout<<N-change-1<<endl;
}
if(sum==0)
{
ll arr_index=0,temp_sum=0,change=0;
for(ll i=arr_index;i<N;i++)
{
temp_sum+=temp[i];
temp[arr_index]=temp_sum;
if((temp[arr_index]==0)&&(i+1<N))
{
arr_index=i+1;
change++;
}
}
cout<<N-change-1<<endl;
}
}
return 0;
}