#include <bits/stdc++.h>
using namespace std;
long long const max1 = 1e5 + 5;
long long const mod = 1e9 + 7;
long long inf = 1e18;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << a[0] << "\n";
      continue;
    } else {
      long long dp1[n], dp2[n];
      dp1[0] = a[0];
      dp2[0] = a[0];
      dp1[1] = a[0] + a[1];
      dp2[1] = a[0];
      for (long long i = 2; i < n; i++) {
        dp1[i] = min(dp2[i - 1] + a[i], dp2[i - 2] + a[i - 1] + a[i]);
        dp2[i] = min(dp1[i - 1], dp1[i - 2]);
      }
      cout << min(dp1[n - 1], dp2[n - 1]) << "\n";
    }
  }
}
