#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str;
    cin >> str;
    int res = 0;
    int num = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '1') {
        num++;
      } else {
        if (num > 1) res += num - 1;
        num = 0;
      }
    }
    if (num) res += num - 1;
    int res1 = 0;
    int num1 = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '0') {
        num1++;
      } else {
        if (num1 > 1) res1 += num1 - 1;
        num1 = 0;
      }
    }
    if (num1) res1 += num1 - 1;
    cout << max(res, res1) << endl;
  }
  return 0;
}
