#include <bits/stdc++.h>
using namespace std;
int minc(int *p, int m) {
  int a = 0, b = m - 1, i, j = 0;
  while (p[a] != 1) {
    a++;
  }
  while (p[b] != 1) {
    b--;
  }
  for (i = a + 1; i < b; i++) {
    if (p[i] == 1) {
      j++;
    }
  }
  if (b - a == 0) {
    return 0;
  } else {
    return (b - a - 1) - j;
  }
}
int main() {
  int n, m, *p, x;
  cin >> n;
  while (n > 0) {
    cin >> m;
    p = new int[m];
    for (int i = 0; i < m; i++) {
      cin >> p[i];
    }
    x = minc(p, m);
    cout << x << endl;
    delete[] p;
    n--;
  }
  return 0;
}
