#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
  return a;
}
int mult(int a, int b) { return a * 1ll * b % MOD; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q) {
    --q;
    long long n;
    cin >> n;
    vector<long long> vec(n);
    for (long long i = 0; i < n; ++i) {
      cin >> vec[i];
    }
    vector<long long> dp(n);
    dp[0] = vec[0];
    if (n > 1) dp[1] = vec[0] + vec[1];
    if (n > 2) dp[2] = vec[0] + vec[2];
    for (int i = 3; i < n; ++i) {
      dp[i] = vec[i];
      dp[i] += min(dp[i - 1], min(dp[i - 2], dp[i - 3]));
    }
    long long res =
        min(dp[max(0ll, n - 1)], min(dp[max(0ll, n - 2)], dp[max(0ll, n - 3)]));
    cout << res << endl;
  }
  return 0;
}
