#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, a, ans = 0, empty = 0;
  bool book = false;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a == 1)
      book = true;
    else if (book)
      empty++;
    if (a == 1 && book) {
      ans += empty;
      empty = 0;
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
