#include <bits/stdc++.h>
using namespace std;
long long t, n;
long long a[200005];
long long dp[200005];
void MainProcess() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = 10000000007;
  }
  if (n <= 2) {
    cout << a[1];
    return;
  }
  dp[1] = a[1];
  dp[2] = a[1] + a[2];
  dp[3] = a[3] + a[1];
  for (long long i = 4; i <= n; i++) {
    dp[i] = min({dp[i - 1], dp[i - 2], dp[i - 3]}) + a[i];
  }
  long long res = min({dp[n], dp[n - 1], dp[n - 2]});
  cout << res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (long long tup = 1; tup <= t; tup++) {
    MainProcess();
    cout << "\n";
  }
  return 0;
}
