#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, p = 0, q, ans1 = 0, ans2 = 0, i;
    cin >> n;
    vector<int> v(n), v2;
    for (i = 0; i < n; i++) {
      cin >> v[i];
      if (v[i] == 1) {
        p++;
        v2.push_back(i + 1);
      }
    }
    if (p == 1)
      cout << "0" << endl;
    else {
      ans1 = v2[0];
      ans2 = v2[p - 1] - p + 1;
      cout << abs(ans1 - ans2) << endl;
    }
  }
  return 0;
}
