#include <bits/stdc++.h>
#pragma optimize("unroll-loops,no-stack-protector")
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long t = 0;
  long long ans = 0;
  ans += a[0];
  for (long long i = 1; i < n; i++) {
    if (a[i] == 1) {
      t++;
    } else {
      ans += t / 3;
      t = 0;
    }
  }
  ans += t / 3;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::ios::sync_with_stdio(false);
  long long te = 1;
  cin >> te;
  while (te--) {
    solve();
  }
}
