#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int a[n];
    for (int j = 0; j < n; j++) {
      cin >> a[j];
    }
    int ans = 0, k = 0, c = 0;
    while (k < n - 2) {
      if (c == 0) {
        if (a[k] == 1) {
          ans++;
        }
        if (a[k + 1] == 0 && a[k + 2] == 1) {
          k += 2;
        } else {
          k++;
        }
        c = 1;
      } else {
        if (a[k + 1] == 0) {
          k++;
        } else {
          k += 2;
        }
        c = 0;
      }
    }
    if (k == n - 1 || k == n - 2) {
      if (c == 0) {
        if (a[k] == 1) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
