#include <bits/stdc++.h>
using namespace std;
template <class X = long long>
inline X min(X a, X b, X c) {
  return min(min(a, b), c);
}
template <class X = long long>
inline X min(X a, X b, X c, X d) {
  return min(min(a, b, c), d);
}
template <class X = long long>
inline X max(X a, X b, X c) {
  return max(max(a, b), c);
}
template <class X = long long>
inline X max(X a, X b, X c, X d) {
  return max(max(a, b, c), d);
}
template <class X = long long>
inline X mid(X s, X e) {
  return (s + (e - s) / 2);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long testcase;
  cin >> testcase;
  while (testcase--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long b, c;
    for (long long i = 0; i < n; i++) {
      if (a[i] == 1) {
        b = i;
        break;
      }
    }
    for (long long i = n - 1; i >= 0; i--) {
      if (a[i] == 1) {
        c = i;
        break;
      }
    }
    long long count = 0;
    for (long long i = b; i <= c; i++) {
      if (a[i] == 0) count++;
    }
    cout << count << "\n";
  }
}
