#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    int cnt = 0;
    for (int i = 0; i < n; i++)
      if (s[i] == 1) cnt++;
    if (cnt == 1)
      cout << 0;
    else {
      cnt = 0;
      int ans = 0, j;
      for (int i = 0; i < n; i++) {
        if (s[i] == 1) {
          j = i;
          break;
        }
      }
      for (int i = j; i < n; i++) {
        if (s[i] == 1) {
          ans += cnt;
          cnt = 0;
        } else
          cnt++;
      }
      cout << ans;
    }
    cout << "\n";
  }
}
