#include <bits/stdc++.h>
using namespace std;
template <class T>
void mxi(T &a, const T &b) {
  a = max(a, b);
}
template <class T>
void mni(T &a, const T &b) {
  a = min(a, b);
}
long double EPS = 1e-9;
long long dp[200200][2], n, ar[200200];
long long go(long long id, long long turn) {
  if (id >= n) return 0;
  long long &e = dp[id][turn];
  if (e == -1) {
    e = 1e18;
    if (turn == 0) {
      if (ar[id] == 1) {
        e = min(e, 1 + go(id + 1, turn ^ 1));
        if (id < n - 1) {
          if (ar[id + 1] == 0) {
            e = min(e, 1 + go(id + 2, turn ^ 1));
          } else {
            e = min(e, 2 + go(id + 2, turn ^ 1));
          }
        }
      } else {
        e = min(e, go(id + 1, turn ^ 1));
        if (id < n - 1) {
          if (ar[id + 1] == 0) {
            e = min(e, go(id + 2, turn ^ 1));
          } else {
            e = min(e, 1 + go(id + 2, turn ^ 1));
          }
        }
      }
    } else {
      e = go(id + 1, turn ^ 1);
      e = min(e, go(id + 2, turn ^ 1));
    }
  }
  return e;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < (n); i++) cin >> ar[i];
  for (long long i = 0; i < (n + 10); i++)
    for (long long j : {0, 1}) dp[i][j] = -1;
  cout << go(0, 0) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, tab;
  cin >> t;
  tab = t;
  while (t--) {
    solve();
  }
}
