#include <bits/stdc++.h>
using namespace std;
const int cdd = 80000000;
int a[300005];
int dp[300005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      dp[i] = cdd;
    }
    dp[1] = a[1];
    dp[2] = dp[1];
    for (int i = 3; i <= n; i++) {
      int min1 = min(dp[i - 2] + a[i - 1], dp[i - 3] + a[i - 2]);
      int min2 =
          min(dp[i - 3] + a[i - 2] + a[i - 1], dp[i - 4] + a[i - 2] + a[i - 3]);
      dp[i] = min(min1, min2);
    }
    int min1 = min(dp[n - 1] + a[n], dp[n - 2] + a[n - 1] + a[n]);
    dp[n] = min(min1, dp[n]);
    cout << dp[n] << endl;
  }
  return 0;
}
