for i in range(int(input())):
    n=int(input())
    s=input()
    if(n==1):
        if(s=='a'):
            print(0)
        else:
            print(1)
    elif(len(set(s[:n//2]))==1 or len(set(s[n//2:]))==1 ):
        print(0)
    else:
        k=n//2
        fa=s[:k].count('a')
        fb=s[:k].count('b')
        la=s[k:].count('a')
        lb=s[k:].count('b')
        if(fa==k and lb==k):
            print(0)
        elif(la==k and fb==k):
            print(0)
        else:
            print(min(((k-fa)+(k-lb)),((k-fb)+(k-la))))
        