#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
ll power(ll x, ll power, ll MOD) {
  ll result = 1;
  while (power) {
    if (power % 2 == 1) result = (result * x) % MOD;
    power = (power >> 1);
    x = (x * x) % MOD;
  }
  return result;
}
void solve(int t) {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int ans = 0;
  for (int i = 0; i < n - 1;) {
    if (arr[i] && arr[i + 1] == 0) {
      int j = i + 1;
      while (arr[j] != 1 && j < n - 1) j++;
      if (arr[j]) ans += j - i - 1;
      i = j;
    } else
      i++;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
