#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int n;
    cin >> n;
    int arr[n];
    int countOne = 0, count = 0;
    bool isFristOne = false, isLastOne = false;
    int firstOneIndex = -1, lastOneIndex = -1;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] == 1) {
        countOne++;
        if (!isFristOne) {
          isFristOne = true;
          firstOneIndex = i;
        } else if (isFristOne && !lastOneIndex) {
          lastOneIndex = i;
        } else {
          lastOneIndex = i;
          isLastOne = true;
        }
      }
    }
    if (firstOneIndex != -1 && isFristOne && isLastOne) {
      for (int i = firstOneIndex; i < lastOneIndex; i++) {
        if (arr[i] == 0) {
          count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
