#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v1;
    bool flag = false;
    int zeroCount = 0;
    vector<int> zeroVec;
    int oneCount = 0;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      v1.push_back(a);
      if (a == 1) {
        oneCount++;
        flag = true;
        zeroVec.push_back(zeroCount);
        zeroCount = 0;
      }
      if (flag == true and a == 0) {
        zeroCount++;
      }
    }
    int count = 0;
    for (int i = 0; i < zeroVec.size(); i++) {
      count += zeroVec[i];
    }
    if (oneCount > 1)
      cout << count << "\n";
    else
      cout << "0\n";
  }
  return 0;
}
