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