#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
void __print(long long int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> arr(n);
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  long long int l = n, r = -1;
  for (long long int i = 0; i < n; i++) {
    if (arr[i] == 1) {
      l = i;
      break;
    }
  }
  for (long long int i = n - 1; n - 1 < -1 ? i < -1 : i > -1;
       n - 1 < -1 ? i += 1 : i -= 1) {
    if (arr[i] == 1) {
      r = i;
      break;
    }
  }
  long long int ans = 0;
  for (long long int i = l; l < r + 1 ? i < r + 1 : i > r + 1;
       l < r + 1 ? i += 1 : i -= 1) {
    if (arr[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
