#include <bits/stdc++.h>
using namespace std;
template <typename T>
T countDigit(T n) {
  return ((n == 0) ? 1 : floor(log10(n) + 1));
}
template <typename T>
T GCD(T a, T b) {
  return ((b % a == 0) ? a : GCD(b % a, a));
}
long long mod_by = 1e18 + 7;
long long binpow(long long a, long long b) {
  a %= mod_by;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod_by;
    a = a * a % mod_by;
    b >>= 1;
  }
  return res;
}
bool sortcol(const vector<long long>& v1, const vector<long long>& v2) {
  return v1[0] < v2[0];
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
pair<long long, long long> comman_range(pair<long long, long long> p1,
                                        pair<long long, long long> p2) {
  long long a = max(p1.first, p2.first), b = min(p1.second, p2.second);
  return (a > b) ? make_pair(-1ll, -1ll) : make_pair(a, b);
}
void solve() {
  cout << fixed << setprecision(9);
  long long t, case_;
  cin >> t;
  case_ = t;
  while (t--) {
    long long n;
    cin >> n;
    std::vector<long long> v(n);
    for (int i = 0; i < n; ++i) {
      cin >> v[i];
    }
    long long g = 0, j = 0;
    long long ans = 0;
    long long jturn = 1;
    for (int i = 0; i < n; ++i) {
      if (jturn == 1) {
        if (j == 0) {
          if (v[i] == 1) ans++;
          j++;
        } else if (j == 1) {
          if (v[i] == 0) {
            jturn = 0;
            j = 0;
          } else {
            j = 0;
            jturn = 0;
            g++;
          }
        }
      } else {
        if (g == 0) {
          g++;
        } else if (g == 1) {
          if (v[i] == 1) {
            g = 0;
            jturn = 1;
          } else {
            g = 0;
            j++;
            jturn = 1;
          }
        }
      }
    }
    g = 0, j = 0;
    long long ans2 = 0;
    jturn = 1;
    for (int i = 0; i < n; ++i) {
      if (jturn == 1) {
        if (j == 0) {
          if (v[i] == 1) ans2++;
          j++;
        } else if (j == 1) {
          if (i < n - 1 && v[i + 1] == 0) {
            jturn = 1;
            j = 0;
          } else if (v[i] == 0) {
            jturn = 0;
            j = 0;
          } else {
            j = 0;
            jturn = 0;
            g++;
          }
        }
      } else {
        if (g == 0) {
          g++;
        } else if (g == 1) {
          if (v[i] == 1) {
            g = 0;
            jturn = 1;
          } else {
            g = 0;
            j++;
            jturn = 1;
          }
        }
      }
    }
    cout << min(ans, ans2) << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
