#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,n,a[3005];
ll cal(ll x)
{
    ll ans=0,res=0;
    int i=1;
    while(i<=n)
    {
        res+=a[i++];
        if(res==x)
        {
            res=0;
            continue;
        }
        if(res>x)
        {
            return n-1;
        }
        ans++;
    }
    return ans;
}
int main(void)
{
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        {
           scanf("%d",&n);
           ll sum=0;
           for(int i=1;i<=n;i++)
           {
               scanf("%d",&a[i]);
               sum+=a[i];
           }
           ll ans=n-1;
           for(ll i=1;i*i<=sum;i++)
           {
               if(sum%i==0)
               {
                   ll a1=cal(i);
                   ll a2=cal(sum/i);
                   ans=min(ans,min(a1,a2));
               }
           }
           printf("%d\n",ans);
        }
    }
	return 0;
}
