#include <bits/stdc++.h>
using namespace std;
const int N = 300500;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long dp[n + 1][3];
    for (int i = n; i >= 0; i--) {
      for (int j = 0; j < 3; j++) {
        if (i == n)
          dp[i][j] = 0;
        else {
          if (arr[i] == 0) {
            dp[i][j] = dp[i + 1][0];
            if (j + 1 < 3) dp[i][j] = min(dp[i][j], dp[i + 1][j + 1]);
          } else {
            dp[i][j] = 1 + dp[i + 1][0];
            if (j + 1 < 3) dp[i][j] = min(dp[i][j], dp[i + 1][j + 1]);
          }
        }
      }
    }
    if (arr[0] == 1)
      cout << 1 + dp[1][0] << endl;
    else
      cout << dp[1][0] << endl;
  }
  return 0;
}
