#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<pair<int, int> > v;
    int pre = a[0];
    int c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == pre) {
        c++;
      } else {
        v.push_back({pre, c});
        c = 1;
        pre = a[i];
      }
    }
    v.push_back({pre, c});
    int ans = 0;
    if (v[0].first == 1) {
      ans++;
      v[0].second--;
      ans += (v[0].second) / 3;
    }
    for (int i = 1; i < v.size(); i++) {
      if (v[i].first == 1) {
        ans += (v[i].second / 3);
      }
    }
    cout << ans << endl;
  }
}
