#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int index1, index2;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      index1 = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (v[i] == 1) {
      index2 = i;
      break;
    }
  }
  if (index1 == index2) {
    cout << count << "\n";
    return;
  }
  for (int i = index1; i <= index2; i++) {
    if (v[i] == 0) count++;
  }
  cout << count << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
