#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e9;
const long long maxn = 2e5 + 1;
const bool debug = 0;
const int64_t INF = 1e17;
const long long module = 1e9 + 7;
void solve() {
  long long n, k1 = 0, k2 = 0;
  cin >> n;
  string s;
  cin >> s;
  for (long long i = 0; (i) < n; ++(i)) {
    if (s[i] == s[(i + 1) % n]) {
      if (s[i] == '1')
        k1++;
      else
        k2++;
    }
  }
  cout << min(k1, k2);
}
int32_t main() {
  if (!debug) {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
  }
  long long tests = 1;
  cin >> tests;
  for (long long _ = 0; (_) < tests; ++(_)) {
    solve();
    cout << "\n";
  }
  return 0;
}
