#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int te;
  cin >> te;
  while (te--) {
    int n;
    cin >> n;
    int cnt = 0;
    set<int> se;
    for (int i = (0); i < (n); i++) {
      int a;
      cin >> a;
      if (a == 1) {
        se.insert(i);
        cnt++;
      }
    }
    cout << *prev(se.end()) - *se.begin() + 1 - cnt << '\n';
  }
}
