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