#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tt = 1;
  cin >> tt;
  long long int kk = 0;
pp:
  for (; kk < tt; kk++) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<char, long long int>> v;
    long long int x = 1, ans0 = 0, ans1 = 0;
    for (long long int i = 1; i < n; i++)
      if (s[i] == s[i - 1])
        x++;
      else {
        v.push_back({s[i - 1], x});
        x = 1;
      }
    v.push_back({s[n - 1], x});
    for (long long int i = 0; i < v.size(); i++)
      if (v[i].first == '0')
        ans0 += v[i].second - 1;
      else
        ans1 += v[i].second - 1;
    cout << max(ans0, ans1) << '\n';
  }
  cerr << "[Execution : " << (1.0 * clock()) / CLOCKS_PER_SEC << "s]\n";
  return 0;
}
