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