#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};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int i = 0;
    int cnt = 0;
    while (i < n) {
      cnt += a[i];
      i++;
      if (i < n and a[i] == 0) i++;
      if (i < n and a[i] == 1) i++;
      if (i < n and a[i] == 1) i++;
    }
    cout << cnt << "\n";
  }
  return 0;
}
