#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
template <typename T>
T binaryExpoWithMod(T x, T y) {
  if (y == 0) return 1;
  if (y % 2 == 0) {
    return (binaryExpoWithMod<T>(x, y / 2) % M *
            binaryExpoWithMod<T>(x, y / 2) % M) %
           M;
  } else {
    return (x % M * binaryExpoWithMod<T>(x, (y - 1) / 2) % M *
            binaryExpoWithMod<T>(x, (y - 1) / 2) % M) %
           M;
  }
}
template <typename T>
T binaryExpo(T x, T y) {
  if (y == 0) return 1;
  if (y % 2 == 0) {
    return binaryExpoWithMod<T>(x, y / 2) * binaryExpoWithMod<T>(x, y / 2);
  } else {
    return x * binaryExpoWithMod<T>(x, (y - 1) / 2) *
           binaryExpoWithMod<T>(x, (y - 1) / 2);
  }
}
template <typename T>
T mul(T x, T y) {
  return (x % M * y % M) % M;
}
template <typename T>
T add(T x, T y) {
  return (x % M + y % M) % M;
}
template <typename T>
void printVector(const vector<T> &vec, const T n) {
  for (T i = 0; i < n; i++) cout << vec[i] << " ";
  cout << "\n";
}
template <typename T>
void printArray(const T *a, const T n) {
  for (T i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
}
template <typename T>
void readVector(vector<T> &vec, const T n) {
  for (T i = 0; i < n; i++) cin >> vec[i];
}
template <typename T>
void readArray(T *a, const T n) {
  for (T i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
T sumOfArray(const T *a, const T n) {
  T c = 0;
  for (T i = 0; i < n; i++) c += a[i];
  return c;
}
template <typename T>
T sumOfVector(const vector<T> &vec, const T n) {
  T c = 0;
  for (T i = 0; i < n; i++) c += vec[i];
  return c;
}
void solve() {
  long long n, i, flag = 0, x, y;
  cin >> n;
  vector<long long> a(n);
  readVector(a, n);
  for (i = 0; i < n; i++) {
    if (a[i] == 1) flag++;
  }
  for (i = 0; i < n; i++)
    if (a[i] == 1) x = i;
  for (i = n - 1; i >= 0; i--)
    if (a[i] == 1) y = i;
  if (flag <= 1) {
    cout << 0 << "\n";
    return;
  }
  long long ans1 = 0, ans2 = 0;
  for (i = y; i <= x; i++)
    if (a[i] == 0) ans1++;
  cout << ans1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int tc = 1;
  cin >> tc;
  while (tc-- > 0) {
    solve();
  }
}
