#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    auto itr = find(arr, arr + n, 1);
    int start = itr - arr;
    long long ans = 0, temp = 0;
    for (int i = start; i < n; i++) {
      if (arr[i]) {
        ans += temp;
        temp = 0;
      } else {
        temp++;
      }
    }
    if (arr[n - 1]) ans += temp;
    cout << ans << "\n";
  }
  return 0;
}
