#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int res[t];
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int arr[n], one = 0, first = 0, zero = 0, temp = 1;
    for (int j = 0; j < n; j++) {
      cin >> arr[j];
      if (arr[j] == 1) one++;
      if (one == 1 and arr[j] == 1) first = j;
    }
    if (one == 1) {
      res[i] = 0;
      continue;
    } else {
      for (int j = first + 1; j < n; j++) {
        if (arr[j] == 0 and temp < one) {
          zero++;
        }
        if (arr[j] == 1 and temp <= one) temp++;
        if (temp == one) {
          break;
        }
      }
      res[i] = zero;
    }
  }
  for (int i = 0; i < t; i++) {
    cout << res[i] << endl;
  }
}
