#include <bits/stdc++.h>
using namespace std;
void read_file() {}
int main() {
  read_file();
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 1;
    int ans = 0;
    for (int i = 1; i < n; ++i) {
      if (s[i] == '1' && s[i - 1] == s[i]) {
        ++cnt;
      } else {
        ans += (cnt - 1);
        cnt = 1;
      }
    }
    ans += (cnt - 1);
    cnt = 1;
    int an = 0;
    for (int i = 1; i < n; ++i) {
      if (s[i] == '0' && s[i - 1] == s[i]) {
        ++cnt;
      } else {
        an += (cnt - 1);
        cnt = 1;
      }
    }
    an += (cnt - 1);
    if (an > 0 && ans > 0)
      cout << max(ans, an) << '\n';
    else if (an > 0)
      cout << an << '\n';
    else if (ans > 0)
      cout << ans << '\n';
    else
      cout << 0 << '\n';
  }
  return 0;
}
