#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 1001;
void print(long long arr[], long long n) {
  for (long long i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
}
void print(int arr[], int n) {
  for (long long i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
}
void print(int arr[], long long n) {
  for (long long i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
}
void print(vector<long long> arr, long long n) {
  for (long long i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
}
vector<long long> pr;
bool prime[1000001];
void SieveOfEratosthenes() {
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= 1000000; i += p) prime[i] = false;
    }
  }
  prime[1] = false;
  for (long long p = 2; p <= 1000000; p++)
    if (prime[p]) pr.push_back(p);
}
long long power(long long a, long long n) {
  long long res = 1, mod = M;
  while (n) {
    if (n % 2) res = (res * a) % mod;
    a = (a * a) % mod;
    n = n / 2;
  }
  return res;
}
long long spf[100001];
void sieve() {
  spf[1] = 1;
  for (long long i = 2; i < 100001; i++) spf[i] = i;
  for (long long i = 4; i < 100001; i += 2) spf[i] = 2;
  for (long long i = 3; i * i < 100001; i++) {
    if (spf[i] == i) {
      for (long long j = i * i; j < 100001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<long long> getFactorization(long long x) {
  vector<long long> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
vector<long long> fact;
void calculate_factorials(long long n) {
  fact.resize(n + 1, 1);
  long long ans = 1;
  for (long long i = 1; i < n + 1; i++) {
    ans = ((ans % M) * (i % M)) % M;
    fact[i] = ans;
  }
}
void init_code() {}
long long dp[200005][2];
vector<long long> a;
long long ok(long long i, long long turn) {
  long long n = a.size();
  if (i >= n) return dp[i][turn] = 0;
  if (dp[i][turn] != -1) return dp[i][turn];
  if (turn) {
    long long mini = 1e9;
    if (i < n && a[i] == 1) mini = min(mini, ok(i + 1, turn ^ 1) + 1);
    if (i < n && a[i] == 0) mini = min(mini, ok(i + 1, turn ^ 1));
    if (i + 1 < n && a[i] == 0 && a[i + 1] == 1)
      mini = min(mini, ok(i + 2, turn ^ 1) + 1);
    if (i + 1 < n && a[i] == 0 && a[i + 1] == 0)
      mini = min(mini, ok(i + 2, turn ^ 1));
    if (i + 1 < n && a[i] == 1 && a[i + 1] == 0)
      mini = min(mini, ok(i + 2, turn ^ 1) + 1);
    if (i + 1 < n && a[i] == 1 && a[i + 1] == 1)
      mini = min(mini, ok(i + 2, turn ^ 1) + 2);
    return dp[i][turn] = mini;
  } else {
    long long mini = 1e9;
    mini = min(ok(i + 1, turn ^ 1), ok(i + 2, turn ^ 1));
    return dp[i][turn] = mini;
  }
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < 2; j++) dp[i][j] = -1;
  }
  for (long long i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    a.push_back(ai);
  }
  ok(0, 1);
  cout << dp[0][1] << endl;
  a.clear();
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  init_code();
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
