#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 10;
vector<int> a;
int dp[N][2];
int solve(int pos, int turn, int n) {
  if (pos == n) {
    return 0;
  }
  if (dp[pos][turn] != -1) {
    return dp[pos][turn];
  }
  int ans = 0;
  if (turn == 0) {
    if ((pos + 1) < n && a[pos] == 0 && a[pos + 1] == 1) {
      ans = min(solve(pos + 1, turn ^ 1, n), 1 + solve(pos + 2, turn ^ 1, n));
    } else if ((pos + 1) < n && (a[pos] == 1 && a[pos + 1] == 0)) {
      ans = 1 + min(solve(pos + 1, turn ^ 1, n), solve(pos + 2, turn ^ 1, n));
    } else if ((pos + 1) < n && (a[pos] == 1 && a[pos + 1] == 1)) {
      ans =
          min(1 + solve(pos + 1, turn ^ 1, n), 2 + solve(pos + 2, turn ^ 1, n));
    } else if ((pos + 1) < n && a[pos] == 0 && a[pos + 1] == 0) {
      ans = min(solve(pos + 1, turn ^ 1, n), solve(pos + 2, turn ^ 1, n));
    } else if ((pos + 1) == n && a[pos] == 0) {
      ans = 0;
    } else if ((pos + 1) == n && a[pos] == 1) {
      ans = 1;
    }
  } else {
    if (pos + 1 < n) {
      ans = min(solve(pos + 1, turn ^ 1, n), solve(pos + 2, turn ^ 1, n));
    } else if (pos + 1 == n) {
      ans = 0;
    }
  }
  return dp[pos][turn] = ans;
}
void solve() {
  int n;
  cin >> n;
  memset(dp, -1, sizeof(dp));
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int res = solve(0, 0, n);
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
