#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  if (count(v.begin(), v.end(), 1) == 1) {
    cout << 0 << endl;
    return;
  }
  int s, e;
  for (s = 0; s < n; s++) {
    if (v[s] == 1) {
      break;
    }
  }
  for (e = n - 1; e >= 0; e--) {
    if (v[e] == 1) {
      break;
    }
  }
  int ans = 0;
  for (int i = s; i <= e; i++) {
    if (v[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
