#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 200007;
int ar[N];
int dp[N][2][2];
int recur(int i, int t, int c) {
  if (i == n) return 0;
  if (dp[i][t][c] == -1) {
    int cost = 0;
    if (t == 0 && ar[i] == 1) cost = 1;
    if (c == 1) {
      dp[i][t][c] = (cost + min(recur(i + 1, t == 0, 1), recur(i + 1, t, 0)));
    } else
      dp[i][t][c] = cost + recur(i + 1, t == 0, 1);
  }
  return dp[i][t][c];
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  cout << recur(0, 0, 1) << '\n';
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  memset(dp, -1, sizeof(dp));
  cin >> t;
  while (t--) {
    solve();
  }
}
