#include <bits/stdc++.h>
using namespace std;
int ans(int ar[], int n) {
  int i = 0, j = n - 1, count = 0;
  while (i < j) {
    if (ar[i] == 1 && ar[j] == 1) {
      break;
    } else if (ar[i] == 1 && ar[j] != 1) {
      j--;
    } else if (ar[j] == 1 && ar[i] != 1) {
      i++;
    } else {
      i++;
      j--;
    }
  }
  if (ar[i] == 1 && ar[j] == 1) {
    while (i != j) {
      if (ar[i] == 0) {
        count++;
        i++;
      } else {
        i++;
      }
    }
  }
  return count;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, r;
    cin >> n;
    int ar[n];
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    r = ans(ar, n);
    cout << r << endl;
  }
  return 0;
}
