#include <bits/stdc++.h>
using namespace std;
long int solve(vector<int>& bosses, long int n, int player,
               vector<vector<long int>>& t);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long int n, i, j, k, l;
    cin >> n;
    vector<int> bosses(n);
    for (i = 0; i < n; i++) cin >> bosses.at(i);
    vector<vector<long int>> t(2, vector<long int>(n + 1, -1));
    cout << solve(bosses, 1, 0, t) << endl;
  }
  return 0;
}
long int solve(vector<int>& bosses, long int n, int player,
               vector<vector<long int>>& t) {
  if (n > bosses.size()) return 0;
  if (n >= bosses.size() - 1 && player == 1) return 0;
  if (n == bosses.size() && player == 0) {
    if (bosses.at(n - 1) == 1)
      return 1;
    else
      return 0;
  }
  if (t.at(player).at(n) != -1) return t.at(player).at(n);
  if (player == 0) {
    if (bosses.at(n - 1) == 1 && bosses.at(n) == 1)
      return t.at(player).at(n) = min(1 + solve(bosses, n + 1, 1, t),
                                      2 + solve(bosses, n + 2, 1, t));
    else if (bosses.at(n - 1) == 0 && bosses.at(n) == 0)
      return t.at(player).at(n) =
                 min(solve(bosses, n + 1, 1, t), solve(bosses, n + 2, 1, t));
    else if (bosses.at(n - 1) == 0 && bosses.at(n) == 1)
      return t.at(player).at(n) = min(solve(bosses, n + 1, 1, t),
                                      1 + solve(bosses, n + 2, 1, t));
    else if (bosses.at(n - 1) == 1 && bosses.at(n) == 0)
      return t.at(player).at(n) = min(1 + solve(bosses, n + 1, 1, t),
                                      1 + solve(bosses, n + 2, 1, t));
  } else
    return t.at(player).at(n) =
               min(solve(bosses, n + 1, 0, t), solve(bosses, n + 2, 0, t));
}
