#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, n;
  cin >> t;
  int a[100010];
  while (t--) {
    cin >> n;
    int ans = 0;
    bool one = false;
    int temp;
    for (int j = 0; j < n; j++) {
      cin >> a[j];
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == 1 && one) {
        ans += (i - temp) - 1;
        temp = i;
      }
      if (a[i] == 1) {
        one = true;
        temp = i;
      }
    }
    cout << ans << endl;
  }
}
