#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, n;
  cin >> t;
  for (int i1 = 0; i1 < t; i1++) {
    cin >> n;
    int sum = 0, f = 0;
    int cur = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        sum += cur;
        f = 1;
        cur = 0;
      } else {
        if (f) {
          cur++;
        }
      }
    }
    cout << sum << endl;
    sum = 0;
  }
}
