#include <iostream>
#define ll long long
using namespace std;

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
        int n;
        cin >> n;
        int *a = new int[n];
        ll sum = 0, max = -1;
        for(int i = 0; i < n; ++i)
        {
            cin >> a[i];
            sum += a[i];
            if(a[i] > max)
                max = a[i];
        }

        int pre = 1;
        int *div = new int[n+1]{};
        div[1] = -1;
        for(int i = 1; i < n; ++i)
            if(sum % (i + 1) == 0)
            {
                if(sum / (i + 1) < max)
                    break;
                div[i+1] = pre;
                pre = i + 1;
            }

        //cout << "pre " << pre << endl;
        //cout << "sum " << sum << endl;
        ll temp = sum / pre, ans = n - 1;
        while(pre > 0)
        {
            temp = sum / pre;
            ll packet = 0;
            for(int i = 0; i < n; ++i)
            {
                packet += a[i];
                if(packet == temp)
                    packet = 0;
                else if(packet > temp)
                    break;
            }
            if(packet == 0)
            {
                ans = n - pre;
                break;
            }
            pre = div[pre];
        }

        cout << ans << endl;

        delete [] a;

	}
	return 0;
}