#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
inline bool equals(long double a, long double b) { return fabs(a - b) < 1e-9; }
inline long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (a > 0 && b > 0) (a > b ? a %= b : b %= a);
  return (a == 0 ? b : a);
}
inline long long power(long long x, long long n, long long m = LLONG_MAX) {
  long long res = 1;
  x = (x % m + m) % m;
  while (n) {
    if (n & 1) res = (res * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return res;
}
long long go(vector<vector<long long>>& dp, long long a[], long long idx,
             long long n, bool fr) {
  if (idx >= n) return 0;
  if (dp[idx][fr] != -1) return dp[idx][fr];
  if (fr) {
    dp[idx][fr] = min(a[idx] + go(dp, a, idx + 1, n, false),
                      a[idx] + a[idx + 1] + go(dp, a, idx + 2, n, false));
  } else {
    dp[idx][fr] = min(go(dp, a, idx + 1, n, true), go(dp, a, idx + 2, n, true));
  }
  return dp[idx][fr];
}
void solve() {
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = 0;
  vector<vector<long long>> dp(n, vector<long long>(2, -1));
  long long ans = go(dp, a, 0, n, true);
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 1; i <= t; ++i) {
    solve();
  };
  return 0;
}
