#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvvvi vector<vvvi>
#define vl vector<ll>
#define vvl vector<vl>
#define vld vector<ld>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define rep(s, l, r) for (int s = l; s < r; s++)
#define per(s, r, l) for (int s = r - 1; s >= l; s--)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> void setmax(T& a, T b) { a = max(a, b); };
template<typename T> void setmin(T& a, T b) { a = min(a, b); };
template<typename T> bool in(T lo, T v, T hi) { return lo <= v && v <= hi; };


struct Solution {
  void solve() {
    int n;
    cin >> n;
    vl a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = n - 1;
    ll sum = accumulate(all(a), 0ll);
    vl targets;
    rep(i, 1, n + 1) {
      if (sum % i == 0) targets.pb(sum / i);
    }
    for (ll x : targets) {
      int ops = 0;
      ll cur = 0;
      bool bad = false;
      rep(i, 0, n) {
        cur += a[i];
        if (cur > x) {
          bad = true; break;
        }
        if (cur - a[i] > 0) ops++;
        if (cur == x) {
          cur = 0;
        }
      }
      if (cur % x != 0) bad = true;
      if (!bad) {
//        cout << "notbad = " << x << " " << ops << endl;
        setmin(ans, ops);
      }
    }
    cout << ans << endl;
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int t; cin >> t;
  while (t--) {
    Solution s;
    s.solve();
  }
  return 0;
}
