#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
void _print(int a) { cerr << a; }
void _print(bool a) { cerr << a; }
void _print(long long a) { cerr << a; }
void _print(string s) { cerr << s; }
template <class T>
void _print(std::vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(std::set<T> s) {
  cerr << "[ ";
  for (T i : s) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(std::multiset<T> s) {
  cerr << "[ ";
  for (T i : s) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
long long mod_add(long long a, long long b, long long M) {
  a = a % M;
  b = b % M;
  return (((a + b) % M) + M) % M;
}
long long mod_mul(long long a, long long b, long long M) {
  a = a % M;
  b = b % M;
  return (((a * b) % M) + M) % M;
}
long long mod_sub(long long a, long long b, long long M) {
  a = a % M;
  b = b % M;
  return (((a - b) % M) + M) % M;
}
bool sortbysec(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.second == b.second) {
    return a.first < b.first;
  }
  return a.second < b.second;
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      l = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (v[i] == 1) {
      r = i;
      break;
    }
  }
  if (l == r) {
    cout << 0 << "\n";
    return;
  }
  int cnt = 0;
  for (int i = l; i <= r; i++) {
    if (v[i] == 0) cnt++;
  }
  cout << cnt << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
}
