#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int k = 0;
    while (a[k] != 1) {
      k++;
    }
    int z = n - 1;
    while (a[z] != 1) {
      z--;
    }
    int flag = 0;
    int count = 0;
    int i = k + 1;
    if (k != z) {
      flag = 1;
    }
    while (i < z) {
      if (a[i] == 1) {
        flag = 1;
      } else if (a[i] == 0) {
        count++;
      }
      i++;
    }
    if (flag == 1) {
      cout << count << "\n";
    } else {
      cout << "0"
           << "\n";
    }
  }
  return 0;
}
