#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long A[n], c = 0;
    for (long long i = 0; i < n; i++) {
      cin >> A[i];
    }
    long long ans = 0, l, r;
    for (long long i = 0; i < n; i++) {
      if (A[i] == 1) {
        l = i;
        break;
      }
    }
    for (long long i = n - 1; i >= 0; i--) {
      if (A[i] == 1) {
        r = i;
        break;
      }
    }
    for (long long i = l; i < r; i++) {
      if (A[i] == 0) {
        ans++;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
