#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    int cur = 1, last = -1, ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] == 1 && cur != 1 && last != -1) {
        ans += i - last - 1;
        cur = 1, last = i;
      } else {
        cur = arr[i];
        if (cur) last = i;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
