#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &elem : a) cin >> elem;
    vector<vector<int>> dp(n, vector<int>(2, -1));
    function<int(int, int)> solve = [&](int idx, int turn) -> int {
      if (idx >= n) {
        return 0;
      }
      if (dp[idx][turn] != -1) return dp[idx][turn];
      int ans = INT_MAX;
      if (turn == 1) {
        if (a[idx] == 1) {
          ans = min(ans, 1 + solve(idx + 1, 0));
          if (idx + 1 < n && a[idx + 1] == 1) {
            ans = min(ans, 2 + solve(idx + 2, 0));
          } else {
            ans = min(ans, 1 + solve(idx + 2, 0));
          }
        } else {
          ans = min(ans, solve(idx + 1, 0));
          if (idx + 1 < n)
            ans = min(ans, (a[idx + 1] == 1) + solve(idx + 2, 0));
        }
      } else {
        ans = min(ans, solve(idx + 1, 1));
        ans = min(ans, solve(idx + 2, 1));
      }
      return dp[idx][turn] = ans;
    };
    cout << solve(0, 1) << endl;
  }
}
