#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 66;
int n, arr[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    vector<pair<int, int>> V;
    for (int i = 1; i <= n;) {
      if (arr[i]) {
        int j = i + 1;
        while (j <= n && arr[j]) ++j;
        V.push_back({i, j - 1});
        i = j;
      } else
        ++i;
    }
    int ans = 0, m = V.size();
    if (m > 1) {
      if (m & 1) {
        int mid = m / 2;
        for (int i = 0; i < mid; ++i) ans += V[i + 1].first - V[i].second - 1;
        for (int i = mid + 1; i < m; ++i)
          ans += V[i].first - V[i - 1].second - 1;
      } else {
        int mid1 = m / 2 - 1, mid2 = m / 2;
        for (int i = 0; i < mid1; ++i) ans += V[i + 1].first - V[i].second - 1;
        for (int i = mid2 + 1; i < m; ++i)
          ans += V[i].first - V[i - 1].second - 1;
        ans += V[mid2].first - V[mid1].second - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
