#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long MOD = 1e9 + 7;
template <class Q>
void clearQueue(Q& q) {
  q = Q();
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long& x : a) cin >> x;
  if (n == 1) {
    if (a[0] == 1)
      cout << 1 << '\n';
    else
      cout << 0 << '\n';
    return;
  }
  long long dp[n][2];
  for (long long i = 0; i < n; i++) {
    dp[i][0] = dp[i][1] = 1e18;
  }
  dp[0][0] = a[0];
  dp[0][1] = 1e18;
  dp[1][0] = a[0] + a[1];
  dp[1][1] = a[0];
  for (long long i = 2; i < n; i++) {
    dp[i][0] = min(a[i] + dp[i - 1][1], a[i] + a[i - 1] + dp[i - 2][1]);
    dp[i][1] = min(dp[i - 1][0], dp[i - 2][0]);
  }
  cout << min(dp[n - 1][0], dp[n - 1][1]) << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}
