#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  int x;
  int first = -1, last = -1;
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (first == -1 && x == 1) {
      first = i;
      last = i;
    } else if (first != -1) {
      if (x == 0) ans++;
      if (x == 1) last = i;
    }
  }
  if (first != last)
    cout << ans - (n - last - 1);
  else
    cout << 0;
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  while (n--) solve();
  return 0;
}
