#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 10;
const long long MOD = 998244353;
const long long INF = 1e9;
long long add(long long x, long long y) {
  x += y;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
long long mul(long long x, long long y) { return (x * 1ll * y) % MOD; }
long long binpow(long long x, long long y) {
  long long ans = 1;
  while (y > 0) {
    if (y % 2 == 1) ans = mul(ans, x);
    x = mul(x, x);
    y /= 2;
  }
  return ans;
}
long long divide(long long x, long long y) {
  return mul(x, binpow(y, MOD - 2));
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v;
  long long one = 0;
  for (long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 1) one++;
    v.push_back(a);
  }
  if (one == 1) {
    cout << 0 << endl;
    return;
  }
  long long res = 0;
  long long index1 = -1;
  long long index2 = -1;
  for (long i = 0; i < n; i++) {
    if (v[i] == 1 && index1 == -1) {
      index1 = i;
      break;
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (v[i] == 1) {
      index2 = i;
      break;
    }
  }
  for (long i = index1; i < index2 + 1; i++) {
    if (v[i] == 0) res++;
  }
  cout << res << endl;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
