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