#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    bool arr[n];
    vector<int> v;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] == 1) v.push_back(i);
    }
    int sum = 0;
    for (int i = 0; i < v.size() - 1; i++) {
      sum += v[i + 1] - v[i] - 1;
    }
    cout << sum << '\n';
  }
}
