#include <bits/stdc++.h>
using namespace std;
void solve() {
  long n;
  cin >> n;
  vector<long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long ans = 0;
  int a = 1;
  long cnt = 0, a1;
  vector<long> b;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      a1 = arr[i];
      cnt++;
    } else {
      if (a1 == arr[i]) {
        cnt++;
      } else {
        a1 = arr[i];
        b.push_back(cnt);
        cnt = 1;
      }
    }
  }
  if (cnt > 0) {
    b.push_back(cnt);
  }
  a1 = arr[0];
  for (int i = 0; i < b.size(); i++) {
    if (a1 == 1) {
      if (a == 1) {
        if (b[i] > 1) {
          ans = ans + (b[i] / 3);
          if (b[i] % 3) {
            ans++;
          }
        } else {
          ans++;
        }
      } else {
        ans = ans + b[i] / 3;
      }
    }
    a1 = a1 ^ 1;
    a = 0;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long t = 1;
  cin >> t;
  while (t--) solve();
}
