#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int has1 = 0;
    int ans = 0;
    int num[n];
    for (int i = 0; i < n; ++i) {
      cin >> num[i];
    }
    int sum = 0;
    int sum1 = 0;
    sum = accumulate(num, num + n, sum);
    int i = 0;
    while (i < n) {
      sum1 += num[i];
      if (num[i] == 1) has1 = 1;
      if (has1 == 1 && sum1 < sum && num[i] == 0) ans += 1;
      ++i;
    }
    cout << ans << endl;
  }
  return 0;
}
