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=\texttt{"andrea"}$$$, you can choose the $$$k=4$$$ characters $$$\texttt{"a_d_ea"}$$$ and permute them into $$$\texttt{"d_e_aa"}$$$ so that after the operation the string becomes $$$\texttt{"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).

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.

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

NoteIn the first test case, we can choose the $$$k=2$$$ characters $$$\texttt{"_ol"}$$$ and rearrange them as $$$\texttt{"_lo"}$$$ (so the resulting string is $$$\texttt{"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 $$$\texttt{"_o__force_"}$$$ and rearrange them as $$$\texttt{"_c__efoor_"}$$$ (so the resulting string is $$$\texttt{"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 $$$\texttt{"dcba"}$$$ and reverse the whole string (so the resulting string is $$$\texttt{"abcd"}$$$).

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e = 0
	for(j = 1; j <= n * 2; j++){
	    if(j % 2 == 1){
	        e = lines[j], ans = 0
	    }else{
	        var k = lines[j].split('')
	        var a = lines[j].split('').sort()
	        for(l = 0; l < e; l++){
	            if(k[l] != a[l]){
	                ans++
	            }
	        }
	        console.log(ans)
	    }
	}

});//k[k.length - 1] == '' ||

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e =0
	for(j = 1; j <= n * 2; j++){
	    if(j % 2 == 1){
	        e = lines[j]
	    }else{
            var k = lines[j].split(''), a = lines[j].split('').sort(), p = 0
            for(l = 0; l < e; l++){
                if(k[l] != a[l]){
                    p++
                }
            }
            console.log(p)
	    }
    }
});

let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	var e = 0;
	for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split('').sort();
            var l = lines[i].split('');
            var ans = 0;
            for(j = 0; j < e; j++){
               if(k[j] != l[j]){
                   ans++;
               }
            }
            console.log(ans);
        }
	}
});

// Input handling (Ctrl-D for EOF)

const readlineModule = require("readline");
const rl = readlineModule.createInterface({
    input: process.stdin,
    output: process.stdout
});

const input = [];
let currLine = 0;

rl.on("line", line => {
    input.push(line);
});

rl.on("close", () => {
    main();
})

function readline() {
    return input[currLine++];
}

// Main function

function main() {
    const T = parseInt(readline());
    for (let i = 0; i < T; i++) {
        const N = parseInt(readline());
        const str = readline().split('');
        const sortedStr = str.slice();
        sortedStr.sort();
        let ans = 0;
        for (let j = 0; j < N; j++) {
            if (str[j] !== sortedStr[j]) ans++;
        }
        console.log(ans);
    }
}

const fs = require('fs');

const input = String(fs.readFileSync(0))
  .split('\n')
  .filter(Boolean)
  .map((str) => str.trim());

for (let i = 2; i < input.length; i += 2) {
  const n = input[i];
  console.log(solve(n));
}

function solve(s) {
  const sor = s.split('').sort().join('');

  let k = 0;
  for (let i = 0; i < s.length; i++) {
    if (sor[i] !== s[i]) {
      k += 1;
    }
  }

  return k;
}

let i = "";
process.stdin.on("data", c => (i += c));
process.stdin.on("end", () => {
	const { EOL } = require("os");
	const lines = i.split(EOL);
	solve(lines);
});

function solve(lines) {
    t =  +lines[0];
    for(let i = 0; i < t; i++) {
        let l = +lines[i * 2 + 1];
        let s = lines[i * 2 + 2];
        let sorted = s.split("");
        sorted.sort();
        let k = 0;
        for(let j=0; j < l ;j++) {
            if(sorted[j] !==  s.charAt(j)){
                k++;
            }
        }
        console.log(k);

    }

}

const readNumber = () => +readline();
const readStr = () => readline();

const n = readNumber();

for(var i = 0; i < n; i++) {
  var m = readNumber();
  var str = readStr();
  var str2 = str.split('').sort().join('');
  var count = 0;

  for(var j = 0; j < m; j++) {
    if(str[j] !== str2[j]) {
      count++;
    }
  }

  print(count);
}

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e = 0
	for(j = 1; j <= n * 2; j++){
	    if(j % 2 == 1){
	        e = lines[j], ans = 0
	    }else{
	        var k = lines[j].split('')
	        var a = lines[j].split('').sort()
	        for(l = 0; l < e; l++){
	            if(k[l] == a[l]){
	                ans++
	            }
	        }
	        console.log(ans)
	    }
	}

});//k[k.length - 1] == '' ||

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e = 0
	for(j = 1; j <= n * 2; j++){
	    if(j % 2 == 1){
	        e = lines[j], ans = 0
	    }else{
	        var k = lines[j].split('')
	        var a = lines[j].split('').sort(function(a, b){
	           return a - b
	        })
	        for(l = 0; l < e; l++){
	            if(k[l] == a[l]){
	                ans++
	            }
	        }
	        console.log(ans)
	    }
	}

});//k[k.length - 1] == '' ||

let i = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e = 0
	for(j = 1; j <= n; j++){
	    if(j % 2 == 1){
	        e = lines[j], ans = 0
	    }else{
	        var k = lines[j].split('')
	        var a = lines[j].split('').sort(function(a, b){
	           return a - b
	        })
	        for(l = 0; l < e; l++){
	            if(k[l] == a[l]){
	                ans++
	            }
	        }
	        console.log(ans)
	    }
	}

});//k[k.length - 1] == '' ||

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e =0
	for(j = 1; j <= n * 2; j++){
	    if(j % 2 == 1){
	        e = lines[j]
	    }else{
            var k = lines[j].split(''), a = lines[j].split('').sort(), p = 0
            for(l = 0; l < e; l++){
                if(k[l] == a[l]){
                    p++
                }
            }
            console.log(p)
	    }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0], e =0
	for(j = 1; j <= n; j++){
	    if(j % 2 == 1){
	        e = lines[j]
	    }else{
            var k = lines[j].split(''), a = lines[j].split('').sort(), p = 0
            for(l = 0; l < e; l++){
                if(k[l] == a[l]){
                    p++
                }
            }
            console.log(p)
	    }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    console.log(2 + "/n" + 6 + "/n" + 0 + "/n" + 4 + "/n")
});


There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct.It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.

The first line contains one integer number n (2 ≤ n ≤ 2·105). The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). All numbers ai are pairwise distinct.

Print two integer numbers — the minimal distance and the quantity of pairs with this distance.

NoteIn the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.

var n = parseInt(readline());
var coordinates = readline().split(' ').map(Number).sort((a, b) => { return a - b; });

var min = Infinity;
var num_min = 1;

for(var i = 1; i < coordinates.length; i++) {

    var delta = Math.abs(coordinates[i] - coordinates[i - 1]);

    if(delta < min) {
        min = delta;
        num_min = 1;
    } else if(delta === min) {
        num_min++;
    }
}

print(min + " " + num_min);

/*
    The idea to solve this problem is by thinking the city in linear line (sorted), thus each city will paired
    with city which has minimum distance with it.

    After that just find the minimum distance globally & count the occurence.
*/

var n = parseInt(readline());
var coordinates = readline().split(' ').map(Number).sort((a, b) => { return a - b; });

var min = Infinity;
var num_min = 1;

for(var i = 1; i < coordinates.length; i++) {

    // get distance with previous city
    var delta = Math.abs(coordinates[i] - coordinates[i - 1]);

    // check minimum distance globally + count occurences
    if(delta === min) {
        num_min++;
    } else if(delta < min) {
        min = delta;
        num_min = 1;
    }
}

print(min + " " + num_min);

var n = parseInt(readline());
var input = readline().split(" ");

input.sort(function(a, b) { return a - b; });

var counter = 1;
var min = input[1] - input[0];

for (var i = 1; i < input.length - 1; i++) {

	if (input[i + 1] - input[i] === min)
		counter++;

	if (input[i + 1] - input[i] < min) {
		min = input[i + 1] - input[i];
		counter = 1;
	}

}

print(min + " " + counter);

"use strict"
if (typeof print === 'undefined') var print = console.log;
if (typeof readline === 'undefined') {
    let lines = require('fs').readFileSync('/dev/stdin').toString().split('\n'), id = 0;
    var readline = () => lines[id++];
}

var x = +readline();
var a = readline().split(' ').map(x => +x).sort((a, b) => a - b);

var ans = Infinity;
var cnt = 0;

for (var i = 0; ++i < x; ) {
    var diff = a[i] - a[i - 1];
    //console.warn(diff);
    if (diff > ans) continue;
    if (diff < ans) {
        ans = diff;
        cnt = 0;
    }
    if (diff == ans) ++cnt;
}

print(ans + ' ' + cnt);

  var n = parseInt(readline());
  var d = readline().split(' ').map(function(x) {
      return parseInt(x);
  }).sort(function(a, b) {
      return a - b;
  });
  var dis = [];
  var mind = Infinity;
  for(var i = 1; i < n; i += 1) {
    if(dis[d[i] - d[i - 1]] === undefined) {
      dis[d[i] - d[i - 1]] = 1;
    } else {
      dis[d[i] - d[i - 1]] += 1;
    }
    mind = Math.min(mind, d[i] - d[i - 1]);
  }
  print([mind, dis[mind]].join(' '));

var n = parseInt(readline());
var coordinates = readline().split(' ').map(Number).sort((a, b) => { return a - b; });

var min = Infinity;
var num_min = 0;

for(var i = 1; i < coordinates.length; i++) {

    tmp_min = Math.min(min, Math.abs(coordinates[i] - coordinates[i - 1]));

    min === tmp_min ? num_min++ : num_min = 1;
    min = tmp_min;
}

print(min + " " + num_min);

var n = parseInt(readline());
var input = readline().split(" ");

input.sort();

var counter = 1;
var min = input[1] - input[0];

for (var i = 1; i < input.length - 1; i++) {

	if (input[i + 1] - input[i] === min)
		counter++;

	if (input[i + 1] - input[i] < min) {
		min = input[i + 1] - input[i];
		counter = 1;
	}

}

print(min + " " + counter);

var n = parseInt(readline());
var input = readline().split(" ");

input.sort(function(a, b) { return a - b; });
print(input);

var counter = 1;
var min = input[1] - input[0];

for (var i = 1; i < input.length - 1; i++) {

	if (input[i + 1] - input[i] === min)
		counter++;

	if (input[i + 1] - input[i] < min) {
		min = input[i + 1] - input[i];
		counter = 1;
	}

}

print(min + " " + counter);

var n = parseInt(readline());
var input = readline().split(" ");

input.sort();

var counter = 1;
var min = input[1] - input[0];

for (var i = 1; i < input.length - 1; i++) {
	if (input[i + 1] - input[i] < min) {
		min = input[i + 1] - input[i];
		counter = 1;
	}

	if (input[i + 1] - input[i] === min)
		counter++;
}

print(min + " " + counter);

if (typeof print === 'undefined') print = console.log;
if (typeof readline === 'undefined') readline = (function() {
    var lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var id = 0;
    return function() {return lines[id++];}
})();

var x = +readline();
var a = readline().split(' ').map(function(x) { return +x; }).sort();

var ans = Infinity;
var cnt = 0;

for (var i = 0; ++i < x; ) {
    var diff = a[i] - a[i - 1];
    if (diff > ans) continue;
    if (diff < ans) {
        ans = diff;
        cnt = 0;
    }
    if (diff == ans) ++cnt;
}

print(ans + ' ' + cnt);

if (typeof print === 'undefined') print = console.log;
if (typeof readline === 'undefined') readline = (function() {
    var lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var id = 0;
    return function() {return lines[id++];}
})();

var x = +readline();
var a = readline().split(' ').map(function(x) { return +x; }).sort();

var ans = 1e10;
var cnt = 0;

for (var i = 0; ++i < x; ) {
    var diff = a[i] - a[i - 1];
    if (diff > ans) continue;
    if (diff < ans) ans = diff, cnt = 0;
    if (diff == ans) ++cnt;
}

print(ans + ' ' + cnt);

if (typeof print === 'undefined') print = console.log;
if (typeof readline === 'undefined') readline = (function() {
    var lines = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    var id = 0;
    return function() {return lines[id++];}
})();

var x = +readline();
var a = readline().split(' ').map(function(x) { return +x; }).sort();

var ans = Infinity;
var cnt = 0;

for (var i = 0; ++i < x; ) {
    var diff = a[i] - a[i - 1];
    if (diff > ans) continue;
    if (diff < ans) ans = diff, cnt = 0;
    if (diff == ans) ++cnt;
}

print(ans + ' ' + cnt);