#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int maxn = 300010;
const long long Mod = 1000000007;
int a[maxn], dp[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int t;
  int n;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      dp[i] = 99999999;
    }
    if (n <= 3) {
      if (a[1] == 1)
        cout << 1 << endl;
      else
        cout << 0 << endl;
      continue;
    }
    dp[1] = a[1];
    dp[2] = dp[1];
    if (a[2] == 1) dp[2]++;
    dp[3] = dp[1];
    if (a[3] == 1) dp[3]++;
    for (int i = 4; i <= n; i++) {
      dp[i] = min(dp[i], dp[i - 2] + a[i]);
      dp[i] = min(dp[i], dp[i - 3] + a[i]);
      if (i >= 5) {
        dp[i] = min(dp[i], dp[i - 4] + a[i] + a[i - 1]);
      }
    }
    cout << min(dp[n - 2], min(dp[n], dp[n - 1])) << endl;
  }
  return 0;
}
