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

int t, n, sum, a[3005];

bool check(int k) {
    if (sum % k != 0) {
        return 0;
    }

    int x = sum / k, cnt = 0, cur = 0;
    for (int i = 0; i < n; i++) {
        cur += a[i];
        if (cur > x) {
            return 0;
        }
        else if (cur == x) {
            cnt++;
            cur = 0;
        }
    }

    return (cnt == k);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> t;
    while (t--) {
        cin >> n;

        sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
        }

        int ans = 1e9;
        for (int i = 1; i <= n; i++) {
            if (check(i)) {
                ans = min(ans, n - i);
            }
        }

        if (ans == 1e9) {
            cout << "-1\n";
        }
        else {
            cout << ans << '\n';
        }
    }

    return 0;
}