#include <bits/stdc++.h>
using namespace std;
void solve() {
  int64_t n, an = 0;
  cin >> n;
  std::vector<int64_t> A(n, 0);
  for (int64_t i = 0; i < n; i++) cin >> A[i];
  an += A[0];
  if (n < 4) {
    cout << an << "\n";
    return;
  }
  for (int64_t i = 3; i < n; i++) {
    if (A[i] == A[i - 1] && A[i] == A[i - 2] && A[i]) an++, A[i] = 0;
  }
  cout << an << "\n";
}
signed main() {
  int64_t T = 1;
  cin >> T;
  while (T--) solve();
  return 0;
}
