#include <bits/stdc++.h>
using namespace std;
void s_y() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  s_y();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int prev = 0;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 0 && prev > 0) {
        ans++;
      }
      if (a[i] == 1) {
        prev++;
      }
    }
    int i = n - 1;
    while (i >= 0 && a[i] == 0) {
      ans--;
      i--;
    }
    cout << ans << "\n";
  }
}
