#include <bits/stdc++.h>
using namespace std;
int a[200050];
int dp[2][200050];
int _min(int x, int y) {
  if (x < y) return x;
  return y;
}
int main() {
  int t, n, i;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      dp[0][i] = 9999999;
      dp[1][i] = 9999999;
    }
    a[0] = 0;
    dp[0][0] = 9999999;
    dp[1][0] = 0;
    if (a[1])
      dp[0][1] = 1;
    else
      dp[0][1] = 0;
    for (i = 2; i <= n; i++) {
      if (a[i] == 1 && a[i - 1] == 1) {
        dp[0][i] = _min(dp[1][i - 1] + 1, dp[1][i - 2] + 2);
      } else if (a[i] == 1 && a[i - 1] == 0) {
        dp[0][i] = _min(dp[1][i - 1] + 1, dp[1][i - 2] + 1);
      } else if (a[i] == 0 && a[i - 1] == 0) {
        dp[0][i] = _min(dp[1][i - 1], dp[1][i - 2]);
      } else if (a[i] == 0 && a[i - 1] == 1) {
        dp[0][i] = _min(dp[1][i - 1], dp[1][i - 2] + 1);
      }
      dp[1][i] = _min(dp[0][i - 1], dp[0][i - 2]);
    }
    printf("%d\n", _min(dp[0][n], dp[1][n]));
  }
  return 0;
}
