#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n;
    cin >> n;
    int lastOne = -1;
    int res = 0;
    for (int j = 0; j < n; ++j) {
      int x;
      cin >> x;
      if (x == 1)
        lastOne = j;
      else if (lastOne >= 0)
        ++res;
    }
    if (lastOne >= 0) res -= n - 1 - lastOne;
    cout << res << '\n';
  }
}
