#include <bits/stdc++.h>
using namespace std;
long long mo(long long a) { return a % (long long)(1e9 + 7); }
long long po(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y >>= 1;
    x = (x * x) % p;
  }
  return res % p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < a.size(); i++) cin >> a[i];
    ;
    vector<long long> sp;
    long long i = 0;
    while (i < n && a[i] == 0) i++;
    for (; i < n; i++) {
      while (i < n && a[i]) i++;
      long long cnt = 0;
      while (i < n && a[i] == 0) {
        cnt++;
        i++;
      }
      sp.push_back(cnt);
    }
    if (a[n - 1] == 0) sp.pop_back();
    long long ans = 0;
    for (long long e : sp) ans += e;
    cout << ans << "\n";
  }
  return 0;
}
