#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  return a.second < b.second;
};
struct compare {
  bool operator()(const int& l, const int& r) { return l > r; }
};
bool prime(int n) {
  if (n == 2) return true;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool pal(string s) {
  int j = s.size() - 1;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[j]) {
      return false;
    }
    j--;
  }
  return true;
}
long long MOD = 1e9 + 7;
long long fast_power(long long x, long long y) {
  if (y == 0) return 1;
  long long temp = fast_power(x, y / 2);
  if (y % 2 != 0)
    temp = (temp * temp * x);
  else
    temp = (temp * temp);
  return temp;
}
vector<int> v1;
long long div(long long n) {
  long long square_root = (long long)sqrt(n) + 1;
  int cou = 0;
  v1.push_back(1);
  v1.push_back(n);
  for (int h = 2; h <= square_root; h++) {
    if (n % h == 0 && h * h != n)
      cou += 2, v1.push_back(h), v1.push_back(n / h);
    else if (n % h == 0 && h * h == n)
      cou += 1, v1.push_back(h), v1.push_back(h);
  }
  return cou;
}
long long sum(long long n) { return (n * (n + 1)) / 2; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n, x;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (x == 1) v.push_back(i + 1);
    }
    long long res = 0;
    for (int i = 1; i < v.size(); i++) {
      res += (v[i] - v[i - 1] - 1);
    }
    cout << res << endl;
  }
  return 0;
}
