#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
int f[N][2];
bool cmp(int a, int b) { return a > b; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    memset(f, 0x3f3f, sizeof f);
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    f[1][0] = a[1];
    f[0][1] = 0;
    for (int i = 2; i <= n; i++) {
      f[i][1] = min(f[i - 1][0], f[i - 2][0]);
      if (a[i] == 0) f[i][0] = min(f[i - 2][1] + a[i - 1], f[i][0]);
      f[i][0] = min(f[i - 1][1] + a[i], f[i - 2][1] + a[i] + a[i - 1]);
    }
    cout << min(f[n][1], f[n][0]) << endl;
  }
  return 0;
}
