#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 5;
template <class T>
void read(vector<T> &arr) {
  for (auto &x : arr) cin >> x;
}
template <class T>
void read(T &x) {
  cin >> x;
}
template <class T>
void write(vector<T> &arr) {
  for (auto x : arr) cout << x << " ";
  cout << "\n";
}
template <class T>
void write(vector<vector<T>> &arr) {
  for (auto &x : arr) {
    for (auto &y : x) cout << y << " ";
    cout << "\n";
  }
}
template <class T>
void write(T &x) {
  cout << x;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  read(arr);
  long long ans = 0;
  long long last = n - 1;
  for (long long i = n - 1; i > -1; --i) {
    if (arr[i] == 1) {
      last = i;
      break;
    }
  }
  bool started = false;
  for (long long i = 0; i <= last; ++i) {
    if (arr[i] == 1) {
      started = true;
    }
    if (arr[i] == 0 && started) {
      ans++;
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
