#include <bits/stdc++.h>
int main() {
  int t;
  std::cin >> t;
  while (t--) {
    int n = 0;
    std::cin >> n;
    std::vector<int> v;
    v.clear();
    for (int i = 0; i < n; i++) {
      int x = 0;
      std::cin >> x;
      v.push_back(x);
    }
    int ones = std::count(v.begin(), v.end(), 1);
    if (ones == 1)
      std::cout << "0\n";
    else {
      int start = std::find(v.begin(), v.end(), 1) - v.begin();
      std::vector<int> v_copy(n);
      std::reverse_copy(v.begin(), v.end(), v_copy.begin());
      int end =
          n -
          ((std::find(v_copy.begin(), v_copy.end(), 1) - v_copy.begin()) + 1);
      int countt = 0;
      bool one_start = false;
      for (int j = start; j <= end; j++) {
        if (v[j] == 1) one_start = true;
        if (v[j] == 0 && one_start == true) {
          countt += 1;
        }
      }
      std::cout << countt << "\n";
    }
  }
  return 0;
}
