#include <bits/stdc++.h>
using namespace std;
long long int f(vector<int>& a) {
  int n = a.size();
  int cnt = 0;
  int last = -1;
  int first = -1;
  for (int i = 0; i < n; i++) {
    int j = i;
    if (a[i] == 1 && first == -1) {
      first = i;
    }
    while (j < n && a[j] == 1) {
      last = j;
      j++;
    }
    if (j - i >= 1) {
      cnt++;
    }
  }
  if (cnt == 1) {
    return 0;
  }
  int res = 0;
  for (int i = first; i <= last; i++) {
    if (a[i] == 0) {
      res++;
    }
  }
  return res;
}
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << f(a) << "\n";
  }
  return 0;
}
