#include <bits/stdc++.h>
using namespace std;
int dp[200005][2];
int n;
vector<int> v(200005);
int memo(int i, int turn) {
  if (i >= n) {
    return dp[i][turn] = 0;
  }
  if (dp[i][turn] != -1) {
    return dp[i][turn];
  }
  if (turn) {
    int skips = 1e9;
    if (i < n && v[i] == 1) {
      skips = min(skips, memo(i + 1, turn ^ 1) + 1);
    }
    if (i < n && v[i] == 0) {
      skips = min(skips, memo(i + 1, turn ^ 1));
    }
    if (i + 1 < n && v[i] == 0 && v[i + 1] == 1) {
      skips = min(skips, memo(i + 2, turn ^ 1) + 1);
    }
    if (i + 1 < n && v[i] == 0 && v[i + 1] == 0) {
      skips = min(skips, memo(i + 2, turn ^ 1));
    }
    if (i + 1 < n && v[i] == 1 && v[i + 1] == 0) {
      skips = min(skips, memo(i + 2, turn ^ 1) + 1);
    }
    if (i + 1 < n && v[i] == 1 && v[i + 1] == 1) {
      skips = min(skips, memo(i + 2, turn ^ 1) + 2);
    }
    return dp[i][turn] = skips;
  } else {
    int skips = 1e9;
    skips = min(memo(i + 1, turn ^ 1), memo(i + 2, turn ^ 1));
    return dp[i][turn] = skips;
  }
}
void fun() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  memset(&dp, -1, sizeof(dp));
  memo(0, 1);
  cout << dp[0][1] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    fun();
  }
}
