# inp.readline()
# int(inp.readline())
# out.write()
# raw_input()
# map(int,raw_input().split())
# map(int,inp.readline().split())
# for _ in xrange(input()):
# print "Case #"+str(_+1)+": "+
if __name__ == "__main__":
    def f(i,j,c,d):
        if i+1==j:
            return int(ord(s[i])-ord('a')!=c)
        if (i,j) not in d:
            d[i,j]=min(f(i,(i+j)/2,c+1,d)+sum(ord(s[k])-ord('a')!=c for k in xrange((i+j)/2,j)),f((i+j)/2,j,c+1,d)+sum(ord(s[k])-ord('a')!=c for k in xrange(i,(i+j)/2)))
        return d[i,j]
    for _ in xrange(input()):
        n=input()
        s=raw_input().strip()
        print f(0,n,0,{})