import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.utf;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip;

		alias mirror = len => s[0..len] ~ s[0..len].byChar.retro.array;

		int len = 1;
		bool first = true;
		int [] cand = [1, n];
		foreach (i; 0..n - 1)
		{
			if (s[i + 1] < s[i])
			{
				cand ~= i + 1;
			}
			if (s[i + 1] > s[i])
			{
				cand ~= i + 1;
				break;
			}
		}
		debug {writeln (cand);}
		cand.map !(mirror).minElement.writeln;
	}
}
