A string $s$ of length $n$, consisting of lowercase letters of the English alphabet, is given.

You must choose some number $k$ between $0$ and $n$. Then, you select $k$ characters of $s$ and permute them however you want. In this process, the positions of the other $n-k$ characters remain unchanged. You have to perform this operation exactly once.

For example, if $s={"andrea"}$, you can choose the $k=4$ characters ${"a_d_ea"}$ and permute them into ${"d_e_aa"}$ so that after the operation the string becomes ${"dneraa"}$.

Determine the minimum $k$ so that it is possible to sort $s$ alphabetically (that is, after the operation its characters appear in alphabetical order).


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 40$) — the length of the string.

The second line of each test case contains the string $s$. It is guaranteed that $s$ contains only lowercase letters of the English alphabet.


-----Output-----

For each test case, output the minimum $k$ that allows you to obtain a string sorted alphabetically, through the operation described above.


-----Examples-----

Input
4
3
lol
10
codeforces
5
aaaaa
4
dcba
Output
2
6
0
4


-----Note-----

In the first test case, we can choose the $k=2$ characters ${"_ol"}$ and rearrange them as ${"_lo"}$ (so the resulting string is ${"llo"}$). It is not possible to sort the string choosing strictly less than $2$ characters.

In the second test case, one possible way to sort $s$ is to consider the $k=6$ characters ${"_o__force_"}$ and rearrange them as ${"_c__efoor_"}$ (so the resulting string is ${"ccdeefoors"}$). One can show that it is not possible to sort the string choosing strictly less than $6$ characters.

In the third test case, string $s$ is already sorted (so we can choose $k=0$ characters).

In the fourth test case, we can choose all $k=4$ characters ${"dcba"}$ and reverse the whole string (so the resulting string is ${"abcd"}$).

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	w = sorted(s)
	count = 0
	for i in range(n):
		if w[i] != s[i]:
			count += 1
	print(count)


for t in range(int(input())):
	n = int(input())
	str = input()
	sstr = sorted(str)
	c = 0
	for i in range(len(str)):
		if str[i] != sstr[i]:
			c = c + 1
	print(c)


import traceback
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
sys.stdin = IOWrapper(sys.stdin)
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import defaultdict as dfd, Counter
from functools import lru_cache
from itertools import accumulate

def geti():
	return int(input())

def gets():
	return input()

def getil():
	return list(map(int, input().split()))

def getsl():
	return input().split()

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r, mod=10 ** 9 + 7):
	num = den = 1
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % mod
		den = den * (i + 1) % mod
	return num * pow(den, mod - 2, mod) % mod

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)

def put(a):
	return ' '.join(map(str, a))
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	(N, a) = getinps('i s')
	b = sorted(list(a))
	return N - sum([i == j for (i, j) in zip(a, b)])
try:
	Test = geti()
	answers = []
	for _ in range(Test):
		ans = main()
		ans = str(ans)
		answers.append(ans)
	print('\n'.join(answers))
except Exception as e:
	print(e)
	traceback.print_exc()


def func(s, n):
	p = []
	for i in s:
		p.append(i)
	q = sorted(p)
	c = 0
	for i in range(n):
		if not p[i] == q[i]:
			c += 1
	print(c)
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	func(s, n)


import sys
MOD = 1000000007

def inp():
	return sys.stdin.readline().strip()

def ii():
	return int(inp())

def iis():
	return [int(i) for i in inp().split()]

def solve():
	n = ii()
	s = list(inp())
	t = sorted(s)
	cnt = 0
	for i in range(n):
		if s[i] != t[i]:
			cnt += 1
	return cnt
t = ii()
for _ in range(t):
	print(solve())


x = int(input())
while x > 0:
	u = int(input())
	n = str(input())
	d = sorted(n)
	s = 0
	for i in range(0, u):
		if n[i] != d[i]:
			s += 1
	x -= 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = sorted(s)
	c = 0
	for i in range(n):
		if s[i] != s1[i]:
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	s = [i for i in input()]
	s1 = sorted(s)
	ans = 0
	for i in range(n):
		if s[i] != s1[i]:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	ss = sorted(s)
	c = 0
	for i in range(n):
		if ss[i] != s[i]:
			c += 1
	print(c)


k = int(input())
while k > 0:
	n = int(input())
	stringul = input()
	stringul_sortat = sorted(stringul)
	raspuns = 0
	for i in range(0, n):
		if stringul[i] != stringul_sortat[i]:
			raspuns = raspuns + 1
	print(raspuns)
	k = k - 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = sorted(s)
	ans = 0
	for i in range(n):
		ans += s[i] != a[i]
	print(ans)


n = int(input())
for i in range(n):
	m = int(input())
	s = input()
	l = []
	k = 0
	for i in s:
		l.append(i)
	l = sorted(l)
	for i in range(len(l)):
		if s[i] != l[i]:
			k += 1
	print(k)


t = int(input())
for _ in range(t):
	l = input()
	s = list(input())
	n = len(s)
	a = s.copy()
	a.sort()
	for i in range(len(s)):
		n -= a[i] == s[i]
	print(n)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input()
	b = sorted(a)
	count = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			count += 1
	print(count)


import sys
INF = float('inf')
MOD = 10 ** 9 + 7
MOD2 = 998244353
from collections import defaultdict

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LC():
	return list(input())

def IC():
	return [int(c) for c in input()]

def MI():
	return map(int, sys.stdin.readline().split())

def solve():
	N = II()
	S = LC()
	Ssort = sorted(S)
	Ans = 0
	for n in range(N):
		if S[n] != Ssort[n]:
			Ans += 1
	return Ans

def main():
	T = II()
	for _ in range(T):
		print(solve())
main()


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	count = 0
	b = sorted(s)
	for i in range(n):
		if s[i] != b[i]:
			count += 1
	print(count)


n = int(input())
for _ in range(n):
	ll = int(input())
	s = list(input())
	_s = sorted(s)
	k = 0
	for i in range(ll):
		if _s[i] != s[i]:
			k += 1
	print(k)


tst = int(input())
for i in range(tst):
	a = int(input())
	b = list(input())
	c = sorted(b)
	ans = 0
	for i in range(a):
		if b[i] != c[i]:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	temp = sorted(s)
	pers = 0
	for j in range(n):
		if s[j] != temp[j]:
			pers += 1
	print(pers)


def solve(s):
	L = list(s)
	L2 = sorted(L)
	count = 0
	for i in range(len(L)):
		if L[i] != L2[i]:
			count += 1
	print(count)
tot = int(input())
for i in range(tot):
	input()
	solve(input())


for s in [*open(0)][2::2]:
	print(sum((x != y for (x, y) in zip(s[:-1], sorted(s[:-1])))))


for i in range(int(input())):
	n = int(input())
	s = input()
	srt = sorted(s)
	ans = 0
	for i in range(n):
		if srt[i] != s[i]:
			ans += 1
	print(ans)


a = int(input())
for j in range(a):
	b = int(input())
	c = list(input())
	d = c.copy()
	d.sort()
	count = 0
	for i in range(b):
		if c[i] == d[i]:
			count += 1
		else:
			pass
	print(b - count)


ans = []
alph = 'abcdefghijklmopqrstuvwxyz'
q = int(input())
for i in range(q):
	l = int(input())
	s = input()
	sn = list(s)
	sn.sort()
	an = 0
	for o in range(l):
		if s[o] != sn[o]:
			an += 1
	ans.append(an)
for i in range(q):
	print(ans[i])


T = int(input())
for t in range(T):
	n = int(input())
	s = list(input())
	k = 0
	switched = [1] * n
	for i in range(n):
		for j in range(n - 1, i, -1):
			if ord(s[i]) > ord(s[j]):
				(s[i], s[j]) = (s[j], s[i])
				k += switched[i] + switched[j]
				(switched[i], switched[j]) = (0, 0)
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	sorted_s = sorted(list(s))
	cnt = 0
	for i in range(n):
		if sorted_s[i] != s[i]:
			cnt += 1
	print(cnt)


p = int(input())
for i in range(p):
	n = int(input())
	a = list(input())
	b = sorted(a)
	f = 0
	i = 0
	while i < n:
		if a[i] != b[i]:
			f = f + 1
		i = i + 1
	print(f)


test_count = int(input())
for _ in range(test_count):
	n = int(input())
	s = list(input())
	sorted_s = sorted(s)
	counter = 0
	for i in range(len(s)):
		if s[i] != sorted_s[i]:
			counter += 1
	print(str(counter))


import math
from collections import defaultdict
from collections import Counter
from math import gcd

def SOE(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for p in range(2, n + 1):
		if prime[p]:
			l += [p]
	return prime

def i1():
	return int(input())

def i2():
	return map(int, input().split())

def i3():
	return list(map(int, input().split()))

def i4():
	return input()

def i5():
	return list(str(input()))

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
ma = 10 ** 9 + 7
for _ in range(i1()):
	n = int(input())
	s = i5()
	b = sorted(s)
	k = 0
	for i in range(0, n):
		if b[i] != s[i]:
			k += 1
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	c = 0
	cs = list(s)
	cs.sort()
	pool = []
	for i in range(len(s)):
		if s[i] != cs[i]:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = input()
	o = ''.join(sorted(list(s)))
	print(n - sum((s[i] == o[i] for i in range(n))))


for q in range(int(input())):
	n = int(input())
	s = input()
	ss = sorted(s)
	cnt = 0
	for i in range(n):
		if s[i] != ss[i]:
			cnt += 1
	print(cnt)


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	s = list(rs())
	ss = sorted(s)
	ans = 0
	for i in range(n):
		ans += s[i] != ss[i]
	print(ans)


x = int(input())
for t in range(x):
	n = int(input())
	s = input()
	ans = 0
	s1 = sorted(s)
	for i in range(len(s)):
		if s[i] != s1[i]:
			ans += 1
	print(ans)


import math
import heapq
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	g = sorted(s)
	g = ''.join(g)
	inPos = {}
	finPos = {}
	for i in range(len(s)):
		try:
			inPos[s[i]].append(i)
		except:
			inPos[s[i]] = [i]
	for i in range(len(s)):
		try:
			finPos[g[i]].append(i)
		except:
			finPos[g[i]] = [i]
	good = 0
	for i in inPos:
		good += len(set(inPos[i]).intersection(set(finPos[i])))
	print(len(s) - good)


n = int(input())
results = []
for i in range(n):
	l = int(input())
	result = l
	s = input()
	sorteds = sorted(s)
	for i in range(l):
		if s[i] == sorteds[i]:
			result -= 1
	results.append(result)
for i in range(n):
	print(results[i])


k = 0
for _ in range(int(input())):
	x = int(input())
	a = input()
	b = sorted(a)
	if a == b:
		print('0')
	else:
		k = sum((str(a[i]) != str(b[i]) for i in range(len(a))))
		print(k)


from sys import stdin
inp = stdin.readline
t = int(inp())
for _ in range(t):
	n = int(inp())
	s = inp()
	count = 0
	x = sorted(s)
	x.append('')
	for (i, c) in enumerate(s):
		if x[i + 1] != c:
			count += 1
	print(count - 1)


def permcheck(s):
	c = 0
	for (i, val) in enumerate(sorted(s)):
		if s[i] != val:
			c += 1
	return c
for _ in range(int(input())):
	n = int(input())
	s = input()
	print(permcheck(s))


test = int(input())
for i in range(test):
	n = int(input())
	string = input()
	arr1 = list(string)
	arr2 = list(sorted(string))
	ans = 0
	for (x, y) in zip(arr1, arr2):
		if x != y:
			ans += 1
	print(ans)


qtd = int(input())
lista = list()
for i in range(0, qtd):
	tam = int(input())
	palavra = input()
	cont = 0
	s = sorted(palavra)
	for i in range(0, tam):
		if palavra[i] != s[i]:
			cont = cont + 1
	lista.append(cont)
for i in range(0, qtd):
	print(lista[i])


from sys import stdin
input = stdin.readline

def answer():
	b = sorted(a)
	count = 0
	for i in range(n):
		if a[i] != b[i]:
			count += 1
	return count
for T in range(int(input())):
	n = int(input().strip())
	a = list(input().strip())
	print(answer())


t1 = int(input())
for _ in range(t1):
	n = int(input())
	s = str(input())
	a = list(map(str, s))
	a.sort()
	p = 0
	for i in range(n):
		if a[i] != s[i]:
			p += 1
	print(p)


t = int(input())
for p in range(t):
	n = int(input())
	s = str(input())
	t = ''.join(sorted(s))
	count = 0
	for i in range(n):
		if s[i] != t[i]:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ss = ''.join(sorted(s))
	ans = sum([0 if s[i] == ss[i] else 1 for i in range(n)])
	print(ans)


(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	s = input().strip()
	t = sorted([c for c in s])
	j = 0
	c = 0
	for i in range(N):
		if s[i] == t[j]:
			j += 1
			continue
		j += 1
		c += 1
	print(c)


def Solve():
	n = int(input())
	s = input()
	p = sorted(s)
	k = 0
	for i in range(len(s)):
		if s[i] != p[i]:
			k += 1
	print(k)
q = int(input())
while q > 0:
	Solve()
	q -= 1


for i in range(int(input())):
	n = int(input())
	s = input()
	c = 0
	ss = ''.join(sorted(s))
	for j in range(n):
		if s[j] != ss[j]:
			c = c + 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = []
	t = input()
	for i in range(n):
		s.append(t[i])
	s.sort()
	count = 0
	for i in range(len(s)):
		if s[i] == t[i]:
			count += 1
	print(len(s) - count)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, s, ss):
	c = 0
	for i in range(n):
		if s[i] != ss[i]:
			c += 1
	print(c)
for _ in range(int(input())):
	n = int(input())
	s = str(input())[:-1]
	ss = sorted(s)
	solve(n, s, ss)


t = int(input())
array_k = []
x = 0
if t >= 1 and t <= 1000:
	for i in range(0, t):
		n = int(input())
		word = str(input())
		word_characters = []
		new_word_characters = []
		for character in word:
			word_characters.append(character)
			new_word_characters.append(character)
		new_word_characters.sort()
		k = 0
		for i in range(0, n):
			if word_characters[i] != new_word_characters[i]:
				k = k + 1
		array_k.append(k)
	for x in array_k:
		print(x)
else:
	{print('')}


t = int(input())
f = []
for i in range(t):
	n = int(input())
	s = input()
	l = list(s)
	y = l.copy()
	y.sort()
	c = 0
	for i in range(len(l)):
		if l[i] == y[i]:
			c = c + 1
	p = len(l) - c
	f.append(p)
for i in f:
	print(i)


def solver(s, n):
	s = list(s)
	s2 = sorted(s)
	count = 0
	for i in range(n):
		if s[i] != s2[i]:
			count += 1
	return count
for _ in range(int(input().strip())):
	n = int(input().strip())
	s = input().strip()
	print(solver(s, n))


t = int(input())
for _ in range(t):
	count = 0
	n = int(input())
	s = list(input())
	k = sorted(s)
	for i in range(n):
		if s[i] != k[i]:
			count += 1
	print(count)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()[:-1]
	ss = sorted(s)
	ans = 0
	for i in range(n):
		if s[i] != ss[i]:
			ans += 1
	print(ans)


t = int(input())
for x in range(0, t):
	(n, s, p) = (int(input()), input(), 0)
	r = s
	s = ''.join(sorted(s))
	for i in range(n):
		if s[i] != r[i]:
			p += 1
	print(p)


t = int(input())
i = 0
while i != t:
	i = i + 1
	n = int(input())
	s = input()
	l = list(s)
	sl = sorted(l)
	ans = n
	for j in range(n):
		if l[j] == sl[j]:
			ans = ans - 1
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = [c for c in input().strip()]
	t = sorted(s)
	ans = 0
	for i in range(len(s)):
		if s[i] != t[i]:
			ans += 1
	print(ans)


def solve():
	n = int(input())
	s = input()
	li = list(s)
	l = li.copy()
	li.sort()
	ans = 0
	for i in range(n):
		if li[i] != l[i]:
			ans += 1
	print(ans)
	return
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	s1 = s.copy()
	s.sort()
	k = 0
	for i in range(n):
		if s1[i] != s[i]:
			k += 1
	print(k)


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10

def solve(N, S):
	T = sorted(S)
	return len([i for i in range(N) if S[i] != T[i]])
T0 = int(input())
for _ in range(T0):
	N = int(input())
	S = input()
	print(solve(N, S))


num_lines = int(input())

def solve(string):
	unique_i = 0
	new_s = sorted(string)
	i = 0
	while i < len(string):
		if new_s[i] != string[i]:
			unique_i += 1
		i += 1
	return unique_i
i = 0
while i < num_lines:
	n = int(input())
	string = list(input())
	print(solve(string))
	i += 1


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	s = list(input().rstrip())
	org = s.copy()
	s.sort()
	cnt = 0
	for i in range(n):
		if not org[i] == s[i]:
			cnt += 1
	print(cnt)


T = int(input())
for t in range(T):
	n = int(input())
	s = input()
	s1 = ''.join(sorted(s))
	c = 0
	for i in range(n):
		if s[i] != s1[i]:
			c += 1
	print(c)


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
for _ in range(ii()):
	n = ii()
	a = list(ip())
	b = a.copy()
	b.sort()
	t = 0
	for i in range(n):
		if a[i] != b[i]:
			t += 1
	print(t)


t = int(input())
while t > 0:
	t -= 1
	num = int(input())
	n = input()
	l1 = [i for i in n]
	l2 = sorted(l1)
	counter = 0
	for i in range(len(n)):
		if l1[i] != l2[i]:
			counter += 1
	print(counter)


import math, bisect, heapq, sys, random
for t in range(int(input())):
	n = int(input())
	a = list(input())
	b = sorted(a)
	c = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			c += 1
	print(c)


def solve():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		sorted_s = sorted(s)
		k = 0
		for j in range(n):
			if s[j] != sorted_s[j]:
				k += 1
		print(k)
solve()


t = int(input())
words = []
for i in range(t):
	n = input()
	w = input()
	words.append([n, w])
for word in words:
	lst = []
	lst[:0] = word[1]
	srt = sorted(lst)
	count = 0
	for i in range(int(word[0])):
		if lst[i] != srt[i]:
			count += 1
	print(count)


t = int(input())
for x in range(t):
	n = int(input())
	s = input()
	k = sorted(s)
	c = 0
	for i in range(n):
		if s[i] != k[i]:
			c += 1
	print(c)


for _ in range(int(input())):
	input()
	s = input()
	ans = 0
	for (i, j) in zip(s, sorted(s)):
		if i != j:
			ans += 1
	print(ans)


reapet_times = int(input())
answer = list()
for repeat in range(reapet_times):
	counter = 0
	sorting = list()
	empty = str()
	horof = int(input())
	str_objest = input()
	for letter in str_objest:
		sorting.append(letter)
		sorting.sort()
	for back in sorting:
		empty += back
	for continuation in range(horof):
		if empty[continuation] != str_objest[continuation]:
			counter += 1
	answer.append(counter)
for finall in answer:
	print(finall)


t = int(input())
for _ in range(t):
	l = int(input())
	s = input()
	res = ''.join(sorted(s))
	count = 0
	j = -1
	for i in range(len(s)):
		j += 1
		if s[i] != res[i]:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = sorted(a)
	c = 0
	for (i, j) in zip(a, b):
		if i != j:
			c += 1
	print(c)


import copy
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	l = [ord(x) for x in s]
	m = copy.copy(l)
	l.sort()
	cnt = 0
	for i in range(0, n):
		if l[i] == m[i]:
			cnt += 1
	print(n - cnt)
	t -= 1


m = int(input())
l = []
for _ in range(m):
	t = int(input())
	a = list(input())
	b = sorted(a)
	c = 0
	for i in range(t):
		if b[i] != a[i]:
			c += 1
	l.append(c)
for i in l:
	print(i)


t = int(input())
for no in range(t):
	n = int(input())
	s = input()
	k = 0
	sorted_characters = sorted(s)
	a_string = ''.join(sorted_characters)
	for i in range(n):
		if s[i] != a_string[i]:
			k += 1
	print(k)


n = int(input())
while n > 0:
	b = int(input())
	s = list(str(input()))
	sort = sorted(s)
	l = 0
	for i in range(0, b):
		if s[i] != sort[i]:
			l += 1
	print(l)
	n -= 1


for t in range(int(input())):
	n = int(input())
	a = list(input())
	b = sorted(a)
	k = 0
	for i in range(n):
		if a[i] != b[i]:
			k += 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	s = input()
	s = list(s)
	a = list(s)
	a.sort()
	c = 0
	for i in range(n):
		if a[i] != s[i]:
			c += 1
	print(c)


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	d = sorted(c)
	count = 0
	for j in range(b):
		if c[j] != d[j]:
			count += 1
	print(count)


T = int(input())
for t in range(T):
	n = int(input())
	s = list(input())
	sorteds = sorted(s)
	ans = 0
	for i in range(n):
		if s[i] != sorteds[i]:
			ans += 1
	print(ans)


import aifc
import os, sys
import math
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	x = int(input())
	y = list(input().strip())
	s = sorted(y)
	cnt = 0
	for t in range(len(y)):
		if s[t] != y[t]:
			cnt += 1
	print(cnt)


n = int(input())
for i in range(n):
	k = 0
	tam = int(input())
	s = input()
	so = sorted(s)
	for i in range(len(s)):
		if so[i] != s[i]:
			k += 1
	print(k)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = 0
	b = ''.join(sorted(s))
	for j in range(n):
		if s[j] != b[j]:
			ans += 1
	print(ans)


n = int(input())
for i in range(n):
	l = int(input())
	a = input()
	b = sorted(a)
	g = 0
	for i in range(l):
		if a[i] != b[i]:
			g = g + 1
	print(g)


import math
t = int(input(''))
for i in range(t):
	n = int(input(''))
	a = input('')
	d = []
	for i in range(len(a)):
		d.append(ord(a[i]) - 97)
	t = 0
	i = 1
	x = list(d)
	x.sort()
	v = 0
	for i in range(len(x)):
		if x[i] != d[i]:
			v += 1
	print(v)


for _ in range(int(input())):
	(x, cnt) = (int(input()), 0)
	s = input()
	check = sorted(s)
	for i in range(x):
		cnt += check[i] != s[i]
	print(cnt)


test = int(input())
answer = []
for i in range(test):
	letters = {}
	n = int(input())
	s = list(input())
	count = 0
	sorteds = sorted(s)
	for l in range(n):
		if sorteds[l] != s[l]:
			count += 1
	answer.append(count)
for d in range(test):
	print(answer[d])


nt = int(input())
ans = []

def soln(s, n):
	s2 = s[:]
	s2.sort()
	count = 0
	for x in range(n):
		if s[x] == s2[x]:
			count = count + 1
	return n - count
for x in range(nt):
	n = int(input())
	s = input()
	ans.append(soln(list(s), n))
for x in ans:
	print(x)


for _ in range(int(input())):
	n = int(input())
	s = list((i for i in input()))
	a = sorted(s)
	ans = 0
	for i in range(n):
		if a[i] != s[i]:
			ans += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	l.sort()
	x = 0
	for i in range(n):
		if s[i] == l[i]:
			x = x + 1
	print(n - x)


import math
import sys
import collections
import bisect
import time
import random
from itertools import permutations

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	n = int(input())
	s = get_string()
	a = sorted(s)
	ans = 0
	for (i, j) in zip(s, a):
		if i != j:
			ans += 1
	print(ans)


n = int(input())
for i in range(n):
	l = int(input())
	a = input().replace('', ' ')[1:-1].split()
	c = a.copy()
	a.sort()
	count = 0
	if c == a:
		print(0)
		continue
	for i in range(l):
		if c[i] != a[i]:
			count += 1
		else:
			pass
	print(count)


t = int(input())
strings = [(int(input()), input()) for _ in range(t)]
ALPHABET = 'abcdefghijklmnopqrstuvwxyz'
for (n, string) in strings:
	counts = [string.count(letter) for letter in ALPHABET]
	positions = [sum(counts[:i]) for i in range(1, 27)]
	k = 0
	for (a, i) in enumerate(string):
		if i == 'a':
			if a >= positions[0]:
				k += 1
		elif not positions[ALPHABET.index(i) - 1] <= a < positions[ALPHABET.index(i)]:
			k += 1
	print(k)


for i in range(int(input())):
	n = int(input())
	s = input()
	temp = sorted(s)
	cnt = 0
	for (i, j) in zip(s, temp):
		if i != j:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	x = list(input())
	y = sorted(x)
	a = 0
	for i in range(n):
		a = a + (x[i] != y[i])
	print(a)


for __ in range(int(input())):
	n = int(input())
	s = list(input())
	s_ = sorted(s)
	count = 0
	for i in range(n):
		if s[i] != s_[i]:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	k = 0
	str_sort = sorted(s)
	for i in range(n):
		if str_sort[i] == s[i]:
			k += 1
	print(n - k)


t = int(input())
for tt in range(t):
	input()
	s = list(input())
	ss = s[:]
	s.sort()
	print(sum([1 for i in range(len(s)) if s[i] != ss[i]]))


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	sorted_s = sorted(s)
	res = 0
	for (s_ch, sorted_s_ch) in zip(s, sorted_s):
		if s_ch != sorted_s_ch:
			res += 1
	print(res)


def Subsequence_Permutation():
	for _ in range(int(input())):
		b = int(input())
		c = input()
		x = 'abcdefghijklmnopqrstuvwxyz'
		y = []
		n = 0
		for i in c:
			y.append(x.index(i))
		z = y[:]
		y.sort()
		for i in range(b):
			if z[i] != y[i]:
				n += 1
		print(n)
Subsequence_Permutation()


casos = int(input())
cont = 0
while cont != casos:
	cont += 1
	n = int(input())
	cadena = str(input())
	lista = list(cadena)
	lista_ordenada = sorted(lista)
	cont2 = 0
	for i in range(0, n):
		if lista[i] != lista_ordenada[i]:
			cont2 += 1
	print(cont2)


t = int(input())
while t > 0:
	n = int(input())
	str1 = input()
	str2 = sorted(str1)
	c = 0
	for i in range(len(str1)):
		if str1[i] != str2[i]:
			c = c + 1
	print(c)
	t = t - 1


t = int(input())
l = []
a = []
for i in range(t):
	rem = input()
	l.append(str(input()))
for i in l:

	def split(i):
		temp = [x for x in i]
		temp.sort()
		return ''.join(temp)
	a.append(split(i))
for (i, j) in zip(l, a):
	c = 0
	for x in range(len(i)):
		if i[x] != j[x]:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	srt = sorted(s)
	ans = len(s)
	for i in range(len(s)):
		if s[i] == srt[i]:
			ans -= 1
	print(ans)


n = int(input())
while n:
	l = int(input())
	s = input()
	S = ''.join(sorted(s))
	a = 0
	for i in range(l):
		if s[i] != S[i]:
			a += 1
	print(a)
	n -= 1


t = int(input())
while t != 0:
	n = int(input())
	s = input()
	ss = sorted(s)
	c = 0
	for i in range(len(s)):
		if ss[i] != s[i]:
			c += 1
	print(c)
	t -= 1


def solution(n, word):
	same = 0
	sorted_word = sorted(word)
	for i in range(n):
		if sorted_word[i] == word[i]:
			same += 1
	return n - same
t = int(input())
for _ in range(t):
	n = int(input())
	word = input()
	print(solution(n, word))


def p(n, st):
	k = 0
	arr = [ord(i) for i in st]
	ars = arr.copy()
	arr.sort()
	for i in range(n):
		if arr[i] != ars[i]:
			k += 1
	return k
a = []
for i in range(int(input())):
	n = int(input())
	st = input()
	a.append(p(n, st))
for i in a:
	print(i)


def solve():
	n = int(input())
	a = input()
	b = ''.join(sorted(a))
	return sum([1 for i in range(n) if a[i] != b[i]])
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


def f(string):
	b = string
	c = [i for i in b]
	c.sort()
	a = ''
	for i in c:
		a += i
	counter = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			counter += 1
	return counter
t = int(input())
for _ in range(t):
	_ = int(input())
	s = input()
	print(f(s))


def solution():
	for t in range(int(input())):
		n = int(input())
		s = input()
		ans = 0
		obj = sorted(s)
		for i in range(n):
			if s[i] != obj[i]:
				ans += 1
		print(ans)
	return
solution()


for i in range(int(input())):
	n = int(input())
	s = input()
	t = sorted(s)
	c = 0
	for j in range(n):
		if s[j] != t[j]:
			c = c + 1
	print(c)


t = int(input())
ans = list()
for i in range(t):
	n = int(input())
	count = 0
	string = input()
	str = ''.join(sorted(string))
	for j in range(n):
		if str[j] != string[j]:
			count += 1
	ans.append(count)
for item in ans:
	print(item)


for _ in range(int(input())):
	n = int(input())
	s = str(input())
	t = sorted(s)
	k = n
	for i in range(n):
		if s[i] == t[i]:
			k -= 1
	print(k)


t = int(input())
for _ in range(t):
	s = int(input())
	S = input()
	(s1, n) = (S, 0)
	S = sorted(S)
	for i in range(len(s1)):
		if S[i] != s1[i]:
			n += 1
	print(n)


for _ in range(int(input())):
	s = input()
	s = input()
	c = ''.join(sorted(s))
	j = 0
	for i in range(len(s)):
		if s[i] != c[i]:
			j += 1
	print(j)


t = int(input())
for j in range(t):
	n = int(input())
	ch = input()
	L = []
	for i in ch:
		L.append(ord(i))
	L = sorted(L, reverse=False)
	r = 0
	for i in range(n):
		if ch[i] != chr(L[i]):
			r += 1
	print(r)


def solve():
	count = 0
	a = sorted(eins)
	for i in range(n):
		if a[i] > eins[i] or a[i] < eins[i]:
			count += 1
	print(count)
t = int(input())
for cases in range(t):
	n = int(input())
	eins = input()
	solve()


for _ in range(int(input())):
	input()
	s = input()
	i = 0
	for (x, y) in zip(sorted(s), s):
		i += x != y
	print(i)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s = input('')
	ss = sorted(s)
	cnt = 0
	for j in range(n):
		if s[j] != ss[j]:
			cnt += 1
	ans.append(cnt)
for answer in ans:
	print(answer)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = str(input())
	lst = []
	lst1 = []
	c = 0
	for i in s:
		lst.append(i)
		lst1.append(i)
	lst.sort()
	for i in range(len(lst)):
		if lst[i] != lst1[i]:
			c = c + 1
	print(c)


for _ in range(int(input())):
	n = input()
	s = list(input())
	l = s.copy()
	l.sort()
	k = 0
	for j in range(len(s)):
		if s[j] != l[j]:
			k += 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = list(s)
	l.sort()
	k = 0
	for i in range(n):
		if l[i] != s[i]:
			k += 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ordered = sorted(s)
	fixed = 0
	for i in range(n):
		if ordered[i] == s[i]:
			fixed += 1
	print(n - fixed)


import sys
nput = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()
	k = sorted(s)
	c = 0
	for i in range(n):
		if s[i] == k[i]:
			c += 1
	print(n - c)


for repeat in range(int(input())):
	n = int(input())
	s = input()
	sortedString = ''.join(sorted(s))
	complement = 0
	for (idx, char) in enumerate(s):
		if char == sortedString[idx]:
			complement += 1
	print(n - complement)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	a = sorted(s)
	count = 0
	for i in range(len(s)):
		if s[i] != a[i]:
			count = count + 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	k = 0
	sorted_s = sorted(s)
	for j in range(n):
		if s:
			if s[j] != sorted_s[j]:
				k += 1
		else:
			break
	print(k)


t = int(input())
for caseNr in range(1, t + 1):
	n = int(input())
	s = str(input())
	s = list(s)
	sorted_s = sorted(s)
	count = 0
	for i in range(len(s)):
		if sorted_s[i] == s[i]:
			count += 1
	print(len(s) - count)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	s1 = []
	for i in s:
		s1.append(i)
	s1.sort()
	c = 0
	for (i, j) in zip(s, s1):
		if i != j:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = input()
	sort_s = sorted(s)
	ans = 0
	for i in range(n):
		if s[i] != sort_s[i]:
			ans += 1
	print(ans)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	s = st()
	x = sorted(s)
	ans = 0
	for i in range(n):
		ans += s[i] != x[i]
	pr(ans)
for _ in range(inp()):
	solve()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	g = sorted(s)
	ans = 0
	for i in range(len(s)):
		if s[i] != g[i]:
			ans += 1
	print(ans)


from sys import *
from bisect import bisect_left
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	n = int(input())
	s = str(input())[:-1]
	t = ''.join(sorted(s))
	ct = 0
	for i in range(n):
		if s[i] != t[i]:
			ct += 1
	print(ct)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	string1 = input()
	string2 = ''.join(sorted(string1))
	count = 0
	for i in range(n):
		if string1[i] != string2[i]:
			count = count + 1
	print(count)


def func(str):
	lst = []
	lst2 = []
	for i in range(len(str)):
		lst.append(str[i])
		lst2.append(str[i])
	lst2.sort()
	k = 0
	for i in range(len(str)):
		if lst[i] == lst2[i]:
			continue
		else:
			k = k + 1
	return k
t = int(input())
for i in range(t):
	l = int(input())
	str = input()
	if l == len(str):
		print(func(str))


import sys
lines = sys.stdin.readlines()
strs = lines[2::2]
for s in strs:
	s1 = list(s.strip())
	s2 = sorted(s1)
	num = sum([e1 != e2 for (e1, e2) in zip(s1, s2)])
	sys.stdout.write(f'{num}\n')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	st = sorted(s)
	dif = 0
	for (ch1, ch2) in zip(s, st):
		if ch1 != ch2:
			dif += 1
	print(dif)


import math

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input()
		s_s = sorted(s)
		k = 0
		for x in range(n):
			if s[x] != s_s[x]:
				k += 1
		print(k)
main()


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = input()
	p = [s[i] for i in range(n)]
	p.sort()
	count = 0
	for i in range(n):
		if s[i] != p[i]:
			count += 1
	print(count)


T = int(input())
while T:
	count = 0
	N = int(input())
	s = input()
	x = s
	sorted_characters = sorted(x)
	x = ''.join(sorted_characters)
	for i in range(N):
		if s[i] != x[i]:
			count = count + 1
	print(count)
	T = T - 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = s
	li = [char for char in b]
	lis = sorted(li)
	c = 0
	for i in range(n):
		if li[i] != lis[i]:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = list(input().strip())
	temp2 = sorted(s)
	count = 0
	for i in range(n):
		if s[i] != temp2[i]:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	arr1 = list(s.strip())
	arr2 = arr1.copy()
	arr2.sort()
	cnt = 0
	for i in range(len(arr1)):
		if arr1[i] == arr2[i]:
			cnt += 1
	print(len(arr1) - cnt)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	p = sorted(s)
	q = ''.join(p)
	a = 0
	for j in range(len(s)):
		if s[j] != q[j]:
			a += 1
	print(a)


t = int(input())
for test in range(t):
	n = int(input())
	s = input()
	arranged = sorted(s)
	if s == arranged:
		print(0)
	else:
		c = 0
		for x in range(n):
			if arranged[x] == s[x]:
				c += 1
		print(n - c)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = 0
	c = sorted(s)
	for i in range(n):
		if ord(s[i]) != ord(c[i]):
			ans += 1
	print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	s2 = s
	s2 = sorted(s)
	k = 0
	for j in range(0, n):
		if not s[j] == s2[j]:
			k += 1
	print(k)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	s1 = sorted(s)
	k = 0
	for i in range(n):
		if s[i] != s1[i]:
			k += 1
	print(k)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	k = sorted(s)
	ans = 0
	for i in range(n):
		if k[i] != s[i]:
			ans += 1
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	s = input()
	t = sorted(s)
	ans = 0
	for i in range(n):
		ans += s[i] != t[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	o = 0
	e = sorted(a)
	for (i, item) in enumerate(a):
		if item != e[i]:
			o += 1
	print(o)


for _ in range(int(input())):
	input()
	s = input()
	print(sum((c1 != c2 for (c1, c2) in zip(s, sorted(s)))))


import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	arr2 = sorted(arr)
	ans = 0
	for (k, kk) in zip(arr, arr2):
		if k != kk:
			ans += 1
	print(ans)


def main():
	numCases = int(input())
	for _ in range(numCases):
		unused_n = int(input())
		inputStr = input()
		unsortedCharArr = list(inputStr)
		sortedCharArr = sorted(list(inputStr))
		cnt = 0
		for (a, b) in zip(unsortedCharArr, sortedCharArr):
			if a != b:
				cnt += 1
		print(cnt)
main()


n = int(input())
for i in range(n):
	t = int(input())
	word = input()
	w = word
	arr = []
	for j in word:
		arr.append(j)
	tab = []
	for j in w:
		tab.append(j)
	tab.sort()
	total = 0
	for j in range(t):
		if tab[j] != arr[j]:
			total = total + 1
	print(total)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	b = sorted(s)
	ans = 0
	for i in range(len(s)):
		if s[i] != b[i]:
			ans += 1
	print(ans)


tests = int(input())
for _ in range(tests):
	n = int(input())
	s = [c for c in input()]
	s_comp = sorted(s)
	ans = 0
	for i in range(n):
		if s[i] != s_comp[i]:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	sortedlist = []
	oglist = []
	k = 0
	length = int(input())
	string = str(input())
	for letter in string:
		oglist.append(letter)
		sortedlist.append(letter)
	sortedlist.sort()
	for i in range(len(oglist)):
		if oglist[i] != sortedlist[i]:
			k += 1
	print(k)


from sys import stdin, stdout
import copy
T = int(stdin.readline())
for _ in range(T):
	a = int(input())
	n = input()
	A = [ord(x) for x in n]
	B = sorted(A)
	c = 0
	for i in range(len(A)):
		if A[i] != B[i]:
			c += 1
	stdout.write(str(c) + '\n')


for i in range(int(input())):
	n = int(input())
	s = list(map(str, input()))
	h = sorted(s)
	c = 0
	for j in range(n):
		if s[j] != h[j]:
			c = c + 1
	print(c)


for i in range(int(input()) * 2):
	t = input()
	if t.isalpha():
		c = 0
		for (a, b) in zip(t, sorted(t)):
			if a != b:
				c += 1
		print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	d1 = {}
	for (i, x) in enumerate(s):
		if x in d1:
			d1[x].add(i)
		else:
			d1[x] = {i}
	s.sort()
	d2 = {}
	for (i, x) in enumerate(s):
		if x in d2:
			d2[x].add(i)
		else:
			d2[x] = {i}
	r = 0
	for x in d1:
		r += len(d2[x] - d1[x])
	print(r)


for _ in range(int(input())):
	n = int(input())
	s = input()
	A = [0] * 26
	for i in range(n):
		A[ord(s[i]) - 97] += 1
	B = []
	for i in range(26):
		B.append([0, 0])
	B[0][1] = A[0]
	for i in range(1, 26):
		B[i][0] = B[i - 1][1]
		B[i][1] = B[i][0] + A[i]
	cnt = 0
	for i in range(n):
		if i < B[ord(s[i]) - 97][1] and i >= B[ord(s[i]) - 97][0]:
			cnt += 1
	print(n - cnt)


t = input()
z = []
length = []
for i in range(int(t)):
	length.append(int(input()))
	z.append(str(input()))

def char_req(p):
	count = 0
	x = list(p)
	y = sorted(x)
	for (a, b) in zip(x, y):
		if a != b:
			count += 1
	return count
for i in z:
	print(char_req(i))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def lebe():
	return list(map(int, input()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def joro(L):
	return ''.join(map(str, L))

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def tr(n):
	return n * (n + 1) // 2

def iu():
	m = so()
	p = st()
	L = []
	for i in p:
		L.append(i)
	L.sort()
	re = 0
	for i in range(len(L)):
		if p[i] != L[i]:
			re += 1
	print(re)

def main():
	for i in range(so()):
		iu()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for i in range(int(input())):
	n = int(input())
	s = [i for i in input()]
	t = sorted(s)
	print(sum([int(s[i] != t[i]) for i in range(n)]))


n = int(input())
for z in range(n):
	m = int(input())
	string = input()
	sort_str = sorted(string)
	dif_count = 0
	for i in range(m):
		if string[i] != sort_str[i]:
			dif_count += 1
	print(dif_count)


for t in range(int(input())):
	n = int(input())
	s = list(input())
	p = sorted(s)
	x = 0
	for i in range(n):
		if s[i] != p[i]:
			x += 1
	print(x)


import sys

def read():
	return sys.stdin.readline().strip()
for _ in range(int(read())):
	n = int(read())
	s = read()
	temp = sorted(s)
	k = 0
	for i in range(n):
		if s[i] != temp[i]:
			k += 1
	print(k)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	ss = sorted(s)
	cnt = 0
	for i in range(len(s)):
		if s[i] != ss[i]:
			cnt += 1
	print(cnt)


def solve():
	n = int(input())
	s = input()
	l = list(s)
	l.sort()
	re = n
	for i in range(n):
		if s[i] == l[i]:
			re -= 1
	print(re)
t = int(input())
for i in range(t):
	solve()


def solve():
	n = int(input())
	s = list(input())
	s1 = sorted(s)
	ans = 0
	for i in range(n):
		ans += s[i] != s1[i]
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	s = list(s)
	r = list(s)
	r.sort()
	ans = 0
	for i in range(n):
		if r[i] != s[i]:
			ans = ans + 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	s = str(input())
	lis = list(s)
	x = [ord(ele) - 96 for ele in lis]
	y = x.copy()
	y.sort()
	for j in range(n):
		if x[j] != y[j]:
			c += 1
	print(c)


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
for _ in range(int(input())):
	n = int(input())
	ar = input()
	k = 0
	t = sorted(ar)
	print(len([i for i in range(n) if ar[i] != t[i]]))


n = int(input())
for i in range(n):
	p = int(input())
	a = input()
	b = sorted(a)
	c = 0
	for i in range(p):
		if a[i] != b[i]:
			c = c + 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	li = list(s)
	sli = sorted(li)
	ctr = 0
	for j in range(n):
		if li[j] != sli[j]:
			ctr += 1
	print(ctr)


t = int(input())
for _ in range(t):
	input()
	test = input()
	print(sum((n != k for (n, k) in zip(test, sorted(test)))))


def prob():
	n = int(input())
	s = input()
	ans = 0
	prev = sorted(s)
	for i in range(n):
		if prev[i] != s[i]:
			ans += 1
	print(ans)
t = 1
t = int(input())
for _ in range(0, t):
	prob()


for _ in range(int(input())):
	bla = input()
	s = input()
	scopy = sorted(s)
	count = 0
	for i in range(len(s)):
		if s[i] != scopy[i]:
			count += 1
	print(count)


t = int(input())
for __ in range(t):
	input()
	a = input()
	print(sum((x != y for (x, y) in zip(a, sorted(a)))))


def y():
	z = input()
	a = input()
	s = sorted(a)
	k = 0
	for i in range(len(a)):
		if s[i] != a[i]:
			k = k + 1
	return k
n = int(input())
m = []
for i in range(n):
	m = m + ['.']
for i in range(n):
	m[i - 1] = y()
for i in range(len(m)):
	print(m[i - 1])


for case in range(int(input())):
	input()
	string = list(input())
	sorted_string = sorted(string)
	count = 0
	for val in range(len(sorted_string)):
		if sorted_string[val] == string[val]:
			count += 1
	print(len(string) - count)


for _ in range(int(input())):
	z = int(input())
	string = list(input())
	two = sorted(string)
	k = 0
	for i in range(z):
		if string[i] != two[i]:
			k += 1
	print(k)


cases = int(input())
for case in range(cases):
	x = input()
	s = input()
	ss = sorted(s)
	ans = 0
	for i in range(len(s)):
		if s[i] != ss[i]:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ls = list(s)
	sls = sorted(ls)
	count = 0
	for i in range(len(ls)):
		if ls[i] != sls[i]:
			count = count + 1
	print(count)


for ii in range(int(input())):
	n = int(input())
	s = input()
	(t, a) = (sorted(s), n)
	for jj in range(n):
		if s[jj] == t[jj]:
			a -= 1
	print(a)


def solve():
	n = int(input())
	s = list(input())
	sc = sorted(s)
	k = 0
	for i in range(n):
		if s[i] != sc[i]:
			k += 1
	return k
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	x = list(input().strip())
	y = sorted(x)
	z = 0
	for i in range(n):
		if x[i] != y[i]:
			z += 1
	print(z)


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr = listStr()
	ans = 0
	for (i, j) in zip(arr, sorted(arr)):
		ans += 1 if i != j else 0
	print(ans)


n_cases = int(input())
while n_cases:
	l_str = int(input())
	string = input()
	sorted_string = sorted(string)
	ans = 0
	for i in range(l_str):
		if string[i] != sorted_string[i]:
			ans += 1
	print(ans)
	n_cases -= 1


TestCases = int(input())
for _ in range(TestCases):
	n = int(input())
	s = input()
	a = sorted(s)
	_s = sum([1 if s[i] != a[i] else 0 for i in range(len(a))])
	print(_s)


n = int(input())
for i in range(n):
	x = int(input())
	s = input()
	y = ''.join(sorted(s))
	c = 0
	for (i, j) in zip(s, y):
		if i != j:
			c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = input()
	d = sorted(s)
	count = 0
	for i in range(n):
		if s[i] != d[i]:
			count += 1
	print(count)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
one = lambda : int(I())
more = lambda : map(int, I().split())
linput = lambda : list(more())
mod = 10 ** 9 + 7
inf = 10 ** 18 + 1

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	return (a + b - 1) // b
for _ in range(one()):

	def solve():
		n = one()
		ans = 0
		s = list(input())
		p = sorted(s)
		for i in range(n):
			if s[i] != p[i]:
				ans += 1
		print(ans)
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	L = list(s)
	L2 = L.copy()
	L2.sort()
	k = 0
	for i in range(len(L)):
		if L[i] != L2[i]:
			k += 1
	print(k)


t = int(input())
for i in range(t):
	length = int(input())
	s = input()
	k = sorted(s)
	f = 0
	for i in range(length):
		if s[i] != k[i]:
			f += 1
	print(f)


t = int(input())
for k in range(t):
	n = int(input())
	s = input()
	s1 = list(s)
	cnt = 0
	for i in range(n):
		for j in range(i, n):
			if s1[i] > s1[j]:
				p = s1[i]
				s1[i] = s1[j]
				s1[j] = p
	for i in range(len(s)):
		if s1[i] != s[i]:
			cnt += 1
	print(cnt)


from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	sorted_s = sorted(s)
	c = 0
	for i in range(n):
		if s[i] != sorted_s[i]:
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	s2 = ''.join(sorted(list(s)))
	ans = 0
	for i in range(n):
		if s[i] != s2[i]:
			ans += 1
	print(ans)


n = int(input())
for i in range(n):
	k = input()
	s = list(input())
	print(sum([1 for (i, j) in zip(s, sorted(s)) if i != j]))


def word(w, n):
	x = 0
	w = n
	a = sorted(w)
	for (i, j) in zip(a, w):
		if i != j:
			x += 1
	return x
task = [word(input(), input()) for _ in range(int(input()))]
print(*task, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ss = sorted(s)
	ret = 0
	for i in range(n):
		if s[i] != ss[i]:
			ret += 1
	print(ret)


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	cnt = []
	while n % 2 == 0:
		cnt.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt.append(i)
			n = n / i
	if n > 2:
		cnt.append(int(n))
	return cnt

def primeFactorsCount(n):
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt += 1
			n = n // i
	if n > 2:
		cnt += 1
	return cnt

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
for xyz in range(0, int(input())):
	n = int(input())
	s = list(input())
	l = sorted(s)
	ans = 0
	for i in range(0, n):
		ans += int(l[i] != s[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = str(input().strip())
	st = sorted(s)
	c = 0
	for (i, j) in zip(s, st):
		if i != j:
			c += 1
	print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'a1' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))
from heapq import *
from collections import deque as dq
from math import ceil, floor, sqrt, pow, factorial, log2
import bisect as bs
from collections import Counter
from itertools import permutations
for _ in range(N()):
	n = N()
	s = S()
	a = sorted(s)
	c = 0
	for i in range(n):
		if s[i] != a[i]:
			c += 1
	print(c)