#include <bits/stdc++.h>
const long long inf = 1e18;
const int32_t M = 1e9 + 7;
const int32_t sze = 1e6 + 1;
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
  for (auto& i : a) out << i << " ";
  return out;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  cin >> v;
  long long ans = 0, l = 0, r = 0;
  for (long long i = 0; i < n; i++)
    if (v[i] == 1) {
      l = i;
      break;
    }
  for (long long i = n - 1; i >= 0; i--)
    if (v[i] == 1) {
      r = i;
      break;
    }
  for (long long i = l; i < r + 1; i++)
    if (v[i] == 0) ans++;
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
