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