#include <bits/stdc++.h>
using namespace std;
int min_moves(string str) {
  int ans = 0, cnt = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '1') {
      cnt++;
    } else {
      ans += max(0, cnt - 1);
      cnt = 0;
    }
  }
  ans += max(0, cnt - 1);
  if (str[0] == '1' and str[0] == str.back()) ans++;
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    string str;
    cin >> n >> str;
    cout << min_moves(str) << endl;
  }
  return 0;
}
