#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, c, x, ans;
  cin >> t;
  while (t--) {
    ans = 0;
    x = -1;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        if (x == -1) {
          x = i;
        } else {
          ans = ans + (i - x - 1);
          x = i;
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
