#include <bits/stdc++.h>
using namespace std;
int dp[200005][2];
int n;
vector<int> a(200005);
int solve(int i, int t) {
  if (i >= n) {
    return dp[i][t] = 0;
  }
  if (dp[i][t] != -1 and i <= n) {
    return dp[i][t];
  }
  if (t == 1) {
    int min1 = 1e9;
    if (i < n and a[i] == 1) {
      min1 = min(min1, solve(i + 1, t ^ 1) + 1);
    }
    if (i < n and a[i] == 0) {
      min1 = min(min1, solve(i + 1, t ^ 1));
    }
    if (i + 1 < n and a[i] == 0 and a[i + 1] == 1) {
      min1 = min(min1, solve(i + 2, t ^ 1) + 1);
    }
    if (i + 1 < n and a[i] == 0 and a[i + 1] == 0) {
      min1 = min(min1, solve(i + 2, t ^ 1));
    }
    if (i + 1 < n and a[i] == 1 and a[i + 1] == 0) {
      min1 = min(min1, solve(i + 2, t ^ 1) + 1);
    }
    if (i + 1 < n and a[i] == 1 and a[i + 1] == 1) {
      min1 = min(min1, solve(i + 2, t ^ 1) + 2);
    }
    return dp[i][t] = min1;
  } else {
    int min1 = 1e9;
    min1 = min(solve(i + 1, t ^ 1), solve(i + 2, t ^ 1));
    return dp[i][t] = min1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, k, l, m, b, t, sum, sum1, flag, max1, tmp;
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 0; i <= n - 1; i++) {
      cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    solve(0, 1);
    cout << dp[0][1] << endl;
  }
}
