#include <bits/stdc++.h>
using namespace std;
void tests() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  int first = -1, second;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (first == -1 && a[i]) first = i;
    if (a[i]) second = i;
  }
  int c = 0, res = 1e7;
  bool found = 0;
  for (int i = first; i < second; i++) {
    if (a[i] == 1) found = 1;
    if (found && !a[i]) c++;
  }
  res = c;
  found = 0, c = 0;
  for (int i = second; i >= first; i--) {
    if (a[i] == 1) found = 1;
    if (found && !a[i]) c++;
  }
  res = min(res, c);
  cout << res << '\n';
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    tests();
  }
  return 0;
}
