#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  int results[t];
  for (int k = 0; k < t; k++) {
    int n;
    scanf("%d", &n);
    int sp = 0;
    int bosses[n + 2];
    for (int j = 0; j < n; j++) {
      scanf("%d", &bosses[j]);
    }
    bosses[n] = 0;
    bosses[n + 1] = 0;
    bool weak = true;
    for (int i = 0; i < n; i++) {
      if (weak) {
        if (bosses[i] == 1 && bosses[i + 1] == 0 && bosses[i + 2] == 0 &&
            bosses[i + 3] == 1) {
          sp++;
          weak = false;
        } else if (bosses[i] == 1 && bosses[i + 1] == 0 && bosses[i + 2] == 0) {
          sp++;
          weak = false;
        } else if (bosses[i] == 1 && bosses[i + 1] == 0 && bosses[i + 2] == 1) {
          sp++;
          i++;
          weak = false;
        } else if (bosses[i] == 1 && bosses[i + 1] == 1) {
          sp++;
          weak = false;
        } else if (bosses[i] == 0 && bosses[i + 1] == 0 && bosses[i + 2] == 0) {
          weak = false;
        } else if (bosses[i] == 0 && bosses[i + 1] == 0) {
          i++;
          weak = false;
        } else if (bosses[i] == 1 && bosses[i + 1] == 0) {
          sp++;
          weak = false;
        } else {
          weak = false;
        }
      } else {
        if (bosses[i] == 1 && bosses[i + 1] == 1) {
          i++;
          weak = true;
        } else if (bosses[i] == 0 && bosses[i + 1] == 1) {
          i++;
          weak = true;
        } else {
          weak = true;
        }
      }
    }
    results[k] = sp;
  }
  for (int k = 0; k < t; k++) {
    cout << results[k] << endl;
  }
  return 0;
}
