#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
void solve() {
  int n;
  cin >> n;
  int ans = 0, t = 0;
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      if (flag) {
        ans += t;
      } else {
        flag = 1;
      }
      t = 0;
    } else
      t++;
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
