#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int a[n], S = 0;
    for (int j = 0; j < n; j++) {
      cin >> a[j];
      if (a[j] == 1) S++;
    }
    if (S < 2) {
      cout << 0 << '\n';
      continue;
    }
    int j = 0;
    while (a[j] == 0) {
      j++;
    }
    int ans = 0;
    for (; j < n; j++) {
      S -= a[j];
      if (S == 0) break;
      ans += a[j] == 0;
    }
    cout << ans << '\n';
  }
  return 0;
}
