#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", 3, "inline")
using namespace std;
int mon[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long gcd(long long x, long long y) {
  return ((y == 0) ? x : gcd(y, x % y));
}
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int n;
bool a[200010];
int x;
int cnt;
inline void solve() {
  long long ans = 0;
  cin >> n;
  cin >> x;
  for (int i = 0; i < n - 1; i++) cin >> a[i];
  a[n - 1] = 0;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      cnt++;
    else {
      ans += (cnt / 3);
      cnt = 0;
    }
  }
  cout << ans + x << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
