#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, long long>& a,
               const pair<long long, long long>& b) {
  return a.second > b.second;
}
long long modulo(long long n, long long m = 1000000007) {
  if (n < 0) {
    return (m - abs(n) % m) % m;
  }
  if (n % m >= 0) return n % m;
  return n % m + m;
  ;
}
bool isPrime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long power(long long a, long long n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  if (n == 2) return (a * a);
  if (n & 1) {
    n--;
    return (a * power(power(a, 2), n / 2));
  } else
    return (power(power(a, 2), n / 2));
}
long long fact(long long n) {
  long long total = 1;
  for (long long i = 2; i < n + 1; i++) {
    total = (total * i) % 1000000007;
  }
  return (total) % 1000000007;
}
long long isLeap(long long i) {
  if (i % 4 == 0) {
    if (i % 100 == 0 && i % 400 != 0) return 0;
    return 1;
  }
  return 0;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v1(n);
  for (long long i = 0; i < n; i++) cin >> v1[i];
  long long l1 = 0, r1 = n, total1 = 0;
  for (long long i = 0; i < n; i++)
    if (v1[i] == 1) {
      l1 = i;
      break;
    }
  for (long long i = n - 1; i >= 0; i--) {
    if (v1[i] == 1) {
      r1 = i;
      break;
    }
  }
  for (long long i = l1; i < r1 + 1; i++) {
    if (v1[i] == 0) total1++;
  }
  cout << total1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  cerr << "time taken : " << (long double)clock() / CLOCKS_PER_SEC << " secs"
       << endl;
  return 0;
}
