#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
long long binpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res % mod;
}
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int inf = 1e9;
const int N = 1e5 + 9;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> a[i];
  if (n == 1) {
    cout << a[0] << "\n";
    return;
  }
  int dp[n][2];
  dp[0][0] = a[0];
  dp[0][1] = 1e9;
  dp[1][0] = a[0] + a[1];
  dp[1][1] = a[0];
  for (__typeof(n) i = (2) - ((2) > (n)); i != (n) - ((2) > (n));
       i += 1 - 2 * ((2) > (n))) {
    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][1], dp[n - 1][0]) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
