#include <bits/stdc++.h>
using namespace std;
void ETA() {
  long long int n, x;
  cin >> n;
  vector<long long int> vec;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    if (i != 0 and x == 1 and vec.back() == 1) continue;
    vec.push_back(x);
  }
  long long int m = vec.size();
  long long int i = 0, j = m - 1, cnt = 0;
  while (i < m and vec[i] == 0) i++;
  while (j >= 0 and vec[j] == 0) j--;
  for (long long int k = i + 1; k < j; k++)
    if (vec[k] == 0) cnt++;
  cout << cnt << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) ETA();
  return 0;
}
