#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    
    string s;
    cin >> s;
    
    int cnt = 0;
    
    for(int i = 0; i < n - 1; i++)
    {
        if(s[i] != s[i + 1])
            cnt ++;
    }
    
    if(cnt > 0 && s[0] == '0')
        cnt --;
        
    cout << cnt << endl;
    
}
int main() {
    // your code goes here
    int t;
    cin >> t;
    
    while(t--)
        solve();
}