#include <bits/stdc++.h>
using namespace std;
void solveTestCase() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<int, int> > cn;
  int C = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      int cnt = 0;
      for (int j = i; j < n; j++) {
        if (a[i] == a[j])
          cnt++;
        else
          break;
      }
      cn.push_back({i, i + cnt - 1});
      i += (cnt - 1);
    }
  }
  int ans = 0;
  for (int i = 1; i < cn.size(); i++) ans += cn[i].first - cn[i - 1].second - 1;
  cout << ans << endl;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solveTestCase();
  }
}
