#include <iostream>
#include <string>
using namespace std;

int main() {
    int t;
    cin >> t; // Read the number of test cases
    while (t--) {
        int n;
        cin >> n; // Read the length of the string
        string s;
        cin >> s; // Read the binary string

        int count_0 = 0, count_1 = 0;
        int transitions = 0;

        // Count the number of '0's and '1's and count transitions
        for (int i = 0; i < n; i++) {
            if (s[i] == '0') {
                count_0++;
                // Check for transition from '1' to '0'
                if (i > 0 && s[i - 1] == '1') {
                    transitions++;
                }
            } else {
                count_1++;
                // Check for transition from '0' to '1'
                if (i > 0 && s[i - 1] == '0') {
                    transitions++;
                }
            }
        }

        // If there are no '0's or no '1's, no moves are needed
        if (count_0 == 0 || count_1 == 0) {
            cout << 0 << endl;
        } else {
            // The number of moves is the number of transitions + 1
            cout << transitions + 1 << endl;
        }
    }
    return 0;
}