#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int shelf[n + 2];
    shelf[0] = -1;
    shelf[n + 1] = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> shelf[i];
    }
    vector<pair<int, int>> group;
    int first = 0;
    for (int i = 1; i <= n + 1; ++i) {
      if (shelf[i] != shelf[i - 1]) {
        if (shelf[i] == 0) {
          if (first > 0) {
            group.push_back({first, i - 1});
          }
        }
        first = i;
      }
    }
    int ans = 0;
    for (int g = 1; g < group.size(); ++g) {
      ans += group[g].first - group[g - 1].second - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
