#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
long long int power(long long int x, long long int y,
                    long long int p = 1000000007) {
  long long int res = 1LL;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1LL) res = (res * x) % p;
    y = y >> 1LL;
    x = (x * x) % p;
  }
  return res;
}
const int maxn = 2e5 + 5;
int dp[maxn][2];
int solve(bool arr[], int i, bool turn, int n) {
  if (i >= n) {
    return 0;
  }
  if (dp[i][turn] != -1) return dp[i][turn];
  int ans = 0;
  if (!turn) {
    if (arr[i] == 1 && arr[i + 1] == 1) {
      ans =
          1 + min(solve(arr, i + 1, !turn, n), 1 + solve(arr, i + 2, !turn, n));
    }
    if (arr[i] == 0 && arr[i + 1] == 1) {
      ans = min(solve(arr, i + 1, !turn, n), 1 + solve(arr, i + 2, !turn, n));
    }
    if (arr[i] == 1 && arr[i + 1] == 0) {
      ans = 1 + min(solve(arr, i + 1, !turn, n), solve(arr, i + 2, !turn, n));
    }
    if (arr[i] == 0 && arr[i + 1] == 0) {
      ans = min(solve(arr, i + 1, !turn, n), solve(arr, i + 2, !turn, n));
    }
  } else {
    ans = min(solve(arr, i + 1, !turn, n), solve(arr, i + 2, !turn, n));
  }
  return dp[i][turn] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i <= n; ++i) {
      dp[i][0] = -1;
      dp[i][1] = -1;
    }
    bool a[n + 1];
    for (int i = 0; i < n; ++i) cin >> a[i];
    a[n] = 0;
    cout << solve(a, 0, false, n) << endl;
  }
  return 0;
}
