#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &arr);
template <typename T>
ostream &operator<<(ostream &os, vector<T> &arr);
int main() {
  (ios_base::sync_with_stdio(false), cin.tie(0));
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    vector<vector<int>> dp(n, vector<int>(2));
    dp[0][0] = a[0];
    dp[0][1] = 1e9 + 5;
    if (n > 1) {
      dp[1][0] = a[0] + a[1];
      dp[1][1] = dp[0][0];
    }
    for (int i = 2; i < n; i++) {
      dp[i][0] = min(dp[i - 1][1] + a[i], dp[i - 2][1] + a[i] + a[i - 1]);
      dp[i][1] = min(dp[i - 1][0], dp[i - 2][0]);
    }
    cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
  }
}
template <typename T>
istream &operator>>(istream &is, vector<T> &arr) {
  typename vector<T>::iterator a;
  for (a = arr.begin(); a != arr.end(); a++) {
    is >> *a;
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &arr) {
  typename vector<T>::iterator a;
  for (a = arr.begin(); a != arr.end(); a++) {
    os << *a << " ";
  }
  os << endl;
  return os;
}
