#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    int left, right;
    for (int i = 0; i < n; i++) {
      if (arr[i] == 1) {
        left = i;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (arr[i] == 1) {
        right = i;
        break;
      }
    }
    int ans = 0;
    if (left == right) {
      cout << 0 << endl;
    } else {
      for (; left < right; left++) {
        if (arr[left] == 0) ans++;
      }
      cout << ans << endl;
    }
  }
}
