#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int n;
    int cnt = 0;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int j = 0; j < n - 2; j++) {
      if (h[j] == 1) {
        for (int k = j + 1; k < n; k++) {
          if (h[k] == 1) {
            cnt += k - j - 1;
            j = k;
          }
        }
      }
    }
    cout << cnt << endl;
    t--;
  }
  return 0;
}
