#include <bits/stdc++.h>
using namespace std;
void solve(int test_number) {
  test_number = test_number;
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> dp(n + 4, 0);
  for (int i = n - 1; i >= 0; --i) {
    dp[i] = a[i] + min({dp[i + 2], dp[i + 3], a[i + 1] + dp[i + 3],
                        a[i + 1] + dp[i + 4]});
  }
  cout << dp[0] << '\n';
}
void solve_explicit(int test_number) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  vector<int> him(n + 1), us(n + 1);
  him[n] = us[n] = 0;
  for (int i = n - 1; i >= 0; --i) {
    us[i] = him[i + 1];
    him[i] = a[i] + us[i + 1];
    if (i < n - 1) {
      us[i] = min(us[i], him[i + 2]);
      him[i] = min(him[i], a[i] + a[i + 1] + us[i + 2]);
    }
  }
  cout << him[0] << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  cin >> T;
  for (int i = 1; i <= T; ++i) solve_explicit(i);
  return 0;
}
