#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void umin(T& x, const U& y) {
  x = min(x, (T)y);
}
template <class T, class U>
void umax(T& x, const U& y) {
  x = max(x, (T)y);
}
template <class T, class U>
void init(vector<T>& v, U x, size_t n) {
  v = vector<T>(n, (T)x);
}
template <class T, class U, typename... W>
void init(vector<T>& v, U x, size_t n, W... m) {
  v = vector<T>(n);
  for (auto& a : v) init(a, x, m...);
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(15);
  if (argc == 2 && atoi(argv[1]) == 123456789)
    freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
  int T = 1;
  cin >> T;
  for (int tt = 1; tt <= T; tt++) {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int>> dp;
    init(dp, 2 * n, n + 2, 2);
    dp[n][0] = dp[n][1] = 0;
    dp[n + 1][0] = dp[n + 1][1] = 0;
    for (int i = n - 1; i >= 0; i--) {
      dp[i][1] = min(dp[i + 1][0], dp[i + 2][0]);
      if (a[i] == 1 && a[i + 1] == 1)
        dp[i][0] = min(1 + dp[i + 1][1], 2 + dp[i + 1][1]);
      else if (a[i] == 1 && a[i + 1] == 0)
        dp[i][0] = min(1 + dp[i + 1][1], 1 + dp[i + 2][1]);
      else if (a[i] == 0 && a[i + 1] == 1)
        dp[i][0] = min(dp[i + 1][1], 1 + dp[i + 2][1]);
      else
        dp[i][0] = min(dp[i + 1][1], dp[i + 2][1]);
    }
    cout << dp[0][0] << endl;
  }
  if (argc == 2 && atoi(argv[1]) == 123456789)
    cout << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
  return 0;
}
