#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long tt;
  cin >> tt;
  while (tt--) {
    long long n, res = 0, f = -1;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      if (f == -1 && a[i]) f = i;
    }
    if (f == -1) {
      cout << 0 << '\n';
      return 0;
    }
    for (long long i = f, cur = 0; i < n; i++) {
      if (a[i]) {
        res += cur;
        cur = 0;
      } else
        cur++;
    }
    cout << res << '\n';
  }
}
