#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int inf = 1e9;
const int NINF = 0xc0c0c0c0;
const int maxn = 2e5 + 7;
const int bas = maxn / 2;
const int Maxn = 1e7 + 7;
const double eps = 1e-6;
const int mod = (1 << 31) - 1;
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T flag = 1;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x = x * flag;
}
int dp[maxn][2][2], a[maxn];
void print(int x) {
  cout << dp[x][0][0] << ' ' << dp[x][0][1] << ' ' << dp[x][1][0] << ' '
       << dp[x][1][1] << endl;
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) memset(dp[i], 0x3f3f3f3f, sizeof dp[i]);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (a[1] == 1) {
    dp[1][1][0] = 1;
  } else {
    dp[1][1][0] = 0;
    dp[1][1][1] = 0x3f3f3f3f;
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] == 1) {
      dp[i][1][0] = min(dp[i - 1][0][1], dp[i - 1][0][0]) + 1;
      dp[i][1][1] = dp[i - 1][1][0] + 1;
      dp[i][0][1] = dp[i - 1][0][0];
      dp[i][0][0] = min(dp[i - 1][1][0], dp[i - 1][1][1]);
    } else {
      dp[i][1][0] = min(dp[i - 1][0][0], dp[i - 1][0][1]);
      dp[i][1][1] = dp[i - 1][1][0];
      dp[i][0][0] = min(dp[i - 1][1][0], dp[i - 1][1][1]);
      dp[i][0][1] = dp[i - 1][0][0];
    }
  }
  int ans = 0x3f3f3f3f;
  ans = min(min(dp[n][0][0], dp[n][0][1]), min(dp[n][1][0], dp[n][1][1]));
  cout << ans << endl;
}
signed main() {
  int T = 1;
  scanf("%d", &T);
  while (T--) solve();
}
