#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    vector<int> v1(n);
    for (int i = 0; i < n; i++) {
      cin >> v1[i];
      if (v1[i] == 1) {
        v.push_back(i + 1);
      }
    }
    int ans = v.back() - v.front() - v.size() + 1;
    cout << ans << endl;
  }
  return 0;
}
