Vasya has a string $s$ of length $n$. He decides to make the following modification to the string:   Pick an integer $k$, ($1 \leq k \leq n$).  For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes through:   qwer (original string)  wqer (after reversing the first substring of length $2$)  weqr (after reversing the second substring of length $2$)  werq (after reversing the last substring of length $2$)  Hence, the resulting string after modifying $s$ with $k = 2$ is werq. 

Vasya wants to choose a $k$ such that the string obtained after the above-mentioned modification is lexicographically smallest possible among all choices of $k$. Among all such $k$, he wants to choose the smallest one. Since he is busy attending Felicity 2020, he asks for your help.

A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:   $a$ is a prefix of $b$, but $a \ne b$;  in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$. 


-----Input-----

Each test contains multiple test cases. 

The first line contains the number of test cases $t$ ($1 \le t \le 5000$). The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \le n \le 5000$) — the length of the string $s$.

The second line of each test case contains the string $s$ of $n$ lowercase latin letters.

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.


-----Output-----

For each testcase output two lines:

In the first line output the lexicographically smallest string $s'$ achievable after the above-mentioned modification. 

In the second line output the appropriate value of $k$ ($1 \leq k \leq n$) that you chose for performing the modification. If there are multiple values of $k$ that give the lexicographically smallest string, output the smallest value of $k$ among them.


-----Example-----
Input
6
4
abab
6
qwerty
5
aaaaa
6
alaska
9
lfpbavjsm
1
p

Output
abab
1
ertyqw
3
aaaaa
1
aksala
6
avjsmbpfl
5
p
1



-----Note-----

In the first testcase of the first sample, the string modification results for the sample abab are as follows :   for $k = 1$ : abab  for $k = 2$ : baba  for $k = 3$ : abab  for $k = 4$ : baba

The lexicographically smallest string achievable through modification is abab for $k = 1$ and $3$. Smallest value of $k$ needed to achieve is hence $1$.

Source: codeforces | Difficulty: MEDIUM
Tags: Constructive algorithms

String algorithms

Sorting

Implementation

Complete search


Solutions:
I = input
for _ in [0] * int(I()):
	n = int(I())
	s = I()
	print(*min(((s[k:] + s[:k][::~n - k & 1 or -1], k + 1) for k in range(n))), sep='\n')


t = int(input())
for j in range(t):
	n = int(input())
	a = input()
	g = a
	b = 0
	for i in range(n):
		d = a[:i]
		if (n - i) % 2 == 0:
			c = a[i:] + d
		else:
			c = a[i:] + d[::-1]
		if c < g:
			g = c
			b = i + 1
	print(g)
	if b == 0:
		print(1)
	else:
		print(b)


from sys import stdin
for _ in range(int(input())):
	n = int(input())
	s = list(stdin.readline().rstrip())
	m = s
	c = 1
	for i in range(2, n + 1):
		if (n - i + 1) % 2 == 0:
			z = s[i - 1:] + s[:i - 1]
		else:
			z = s[i - 1:] + s[:i - 1][::-1]
		if z < m:
			m = z
			c = i
	print(''.join(m))
	print(c)


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	lis = [(s, 1)]
	for i in range(2, n):
		if (n - i) % 2 == 1:
			lis.append((s[i - 1:] + s[:i - 1], i))
		else:
			lis.append((s[i - 1:] + s[:i - 1][::-1], i))
	lis.append((s[::-1], n))
	lis.sort()
	print(lis[0][0])
	print(lis[0][1])


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	stri = input()
	stri = stri[0:n]
	z = 'z' * 50002
	if n == 1:
		print(stri)
		print(1)
	else:
		count = 0
		if n % 2 == 1:
			for i in range(1, n + 1):
				if i % 2 == 0:
					s = stri[i - 1:] + stri[:i - 1]
					if s < z:
						z = s
						count = i
				else:
					s = stri[i - 1:n] + stri[0:i - 1][::-1]
					if s < z:
						z = s
						count = i
		else:
			for i in range(1, n + 1):
				if i % 2 == 1:
					s = stri[i - 1:] + stri[:i - 1]
					if s < z:
						z = s
						count = i
				else:
					s = stri[i - 1:n] + stri[0:i - 1][::-1]
					if s < z:
						z = s
						count = i
		print(''.join(z))
		print(count)


import sys
input = sys.stdin.readline
t = int(input())
from collections import defaultdict as dd
while t:
	n = int(input())
	s = input()
	s = s[:n]
	mi = s
	ind = 0
	for i in range(n):
		a = i
		d = n - 1 - a
		if d % 2:
			s1 = s[a:] + s[:a]
		else:
			ss = ''
			if a - 1 >= 0:
				ss = s[:a]
				ss = ss[::-1]
			s1 = s[a:] + ss
		if s1 < mi:
			mi = s1
			ind = a
	print(mi)
	print(ind + 1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = input()
	ans = 0
	b = a
	for i in range(1, n):
		if (n - i + 1) % 2 == 1:
			s = a[i:] + a[:i]
			if s < b:
				b = s
				ans = i
		else:
			s = a[i:] + a[:i][::-1]
			if s < b:
				b = s
				ans = i
	print(b)
	print(ans + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	store = []
	store.append((s, 1))
	store.append((s[::-1], n))
	for k in range(1, n - 1):
		first = s[k:]
		second = s[:k]
		total = n - k
		if total % 2 == 1:
			second = second[::-1]
		store.append((first + second, k + 1))
	store = sorted(store, key=lambda x: (x[0], x[1]))
	print(store[0][0])
	print(store[0][1])


for _ in range(int(input())):
	n = int(input())
	f = input()
	k = 1
	an = f
	for i in range(1, n + 1):
		if i == n:
			s = f[::-1]
		elif (n - i + 1) % 2 == 0:
			s = f[i - 1:] + f[:i - 1]
		else:
			s = f[i - 1:] + f[:i - 1][::-1]
		if s < an:
			an = s
			k = i
	print(an)
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	t = s[::-1]
	can = []
	for i in range(n):
		tmp = s[i:]
		if i == 0:
			can.append([s, 1])
			continue
		if i % 2 != n % 2:
			tmp += t[-i:]
		else:
			tmp += s[:i]
		can.append([tmp, i + 1])
	print(min(can)[0])
	print(min(can)[1])


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	li = []
	for k in range(n - 1):
		if (n - k + 2) % 2 == 0:
			li.append((s[k:] + s[:k], k + 1))
		else:
			li.append((s[k:] + s[:k][::-1], k + 1))
	li.append((s[::-1], n))
	(s, k) = min(li)
	print(s)
	print(k)


T = int(input())
for _ in range(T):
	n = int(input())
	word = input()
	minChar = ord('z') + 1
	minIndex = n + 10
	candidates = []
	for i in range(n):
		if ord(word[i]) < minChar:
			minChar = ord(word[i])
			candidates = [(word[i:], i)]
		elif ord(word[i]) == minChar:
			candidates.append((word[i:], i))
	candidates2 = []
	for (c, i) in candidates:
		candidates2.append((c + word[:i], i) if abs(n - i) % 2 == 0 else (c + word[:i][::-1], i))
	best = min(candidates2)
	print(best[0])
	print(best[1] + 1)


def getModifyStrig(s, k, n):
	pre = s[k - 1:]
	suff = s[0:k - 1]
	if (n - (k - 1)) % 2 == 1:
		suff = suff[::-1]
	return pre + suff
test = int(input().strip())
while test != 0:
	n = int(input().strip())
	s = input().strip()
	ans = getModifyStrig(s, 1, n)
	k = 1
	for i in range(2, n + 1):
		temp = getModifyStrig(s, i, n)
		if temp < ans:
			ans = temp
			k = i
	print(ans)
	print(k)
	test -= 1


s = int(input())
for i in range(s):
	n = int(input())
	s1 = input()
	ans = 1
	s2 = s1
	for j in range(2, n + 1):
		s3 = s1[0:j - 1]
		s4 = s1[j - 1:n]
		if (n - j) % 2 == 0:
			s3 = s3[::-1]
		s5 = s4 + s3
		if s5 < s2:
			s2 = s5
			ans = j
		j += j
	print(s2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	word = input()
	ans = []
	for i in range(1, n + 1):
		if i == n:
			temp = word[-1::-1]
		elif (n - i + 1) % 2 == 0:
			temp = word[i - 1:] + word[:i - 1]
		else:
			temp = word[i - 1:] + word[:i - 1][::-1]
		ans.append([temp, i])
	m = ans[0][0]
	u = 1
	for i in range(1, len(ans)):
		if ans[i][0] < m:
			m = ans[i][0]
			u = ans[i][1]
	print(m)
	print(u)


for _ in range(int(input())):
	n = int(input())
	s = input()
	z = []
	for i in range(n):
		if (n - i) % 2:
			z.append([s[i:] + s[:i][::-1], i])
		else:
			z.append([s[i:] + s[:i], i])
	z.sort()
	print(z[0][0])
	print(z[0][1] + 1)


def all_rotates(s, k):
	return s[k - 1:] + (s[:k - 1] if (len(s) + k) % 2 == 1 else s[:k - 1][::-1])

def solution(s):
	min_idx = 0
	(ans_k, ans_ex) = (1, s)
	for i in range(1, len(s)):
		try_ex = all_rotates(s, i + 1)
		if s[i] < s[min_idx] or (s[i] == s[min_idx] and try_ex < ans_ex):
			min_idx = i
			ans_ex = try_ex
	return (min_idx + 1, ans_ex)
T = int(input())
for _ in range(T):
	sz = int(input())
	s = input()
	(k, ex) = solution(s)
	print(ex)
	print(k)


t = int(input())
while t > 0:
	dic = {}
	t -= 1
	n = int(input())
	STR = input()
	arr = [0] * n
	for i in range(n):
		arr[i] = ord(STR[i])
	m_val = 10000000
	for i in range(n):
		if arr[i] < m_val:
			m_val = arr[i]
	arr2 = []
	for i in range(n):
		if arr[i] == m_val:
			arr2.append(i)
	for i in arr2:
		s1 = ''
		if i == 0:
			s1 = STR
		elif i == n - 1:
			s1 = STR[::-1]
		elif (n - i) % 2 == 1:
			s1 = STR[i:] + STR[:i][::-1]
		else:
			s1 = STR[i:] + STR[:i]
		if s1 in dic:
			dic[s1] = min(dic[s1], i + 1)
		else:
			dic[s1] = i + 1
	temp = dic.keys()
	s3 = min(temp)
	print(s3)
	print(dic[s3])


def rev(s):
	return s[::-1]

def parity(n, k):
	return True if n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1) else False
for t in range(int(input())):
	n = int(input())
	s = input()
	ans = s
	ansk = 1
	for k in range(2, n + 1):
		c = s[k - 1:]
		if parity(n, k):
			c += rev(s[:k - 1])
		else:
			c += s[:k - 1]
		if c < ans:
			ans = c
			ansk = k
	print(ans)
	print(ansk)


def rev(a):
	return a[::-1]

def perm(s, n):
	if (len(s) - n) % 2:
		return s[n - 1:] + s[:n - 1]
	else:
		return s[n - 1:] + rev(s[:n - 1])

def calc(s):
	if len(s) < 2:
		return (s, 1)
	li = []
	d = min(s)
	ran = []
	for k in range(len(s)):
		if s[k] == d:
			ran.append(k + 1)
	if len(ran) == len(s):
		return (s, 1)
	for j in ran:
		li.append((perm(s, j), j))
	li.sort()
	mini = li[0][0]
	anss = li[0][1]
	for j in li:
		if mini == j[0]:
			anss = min(anss, j[1])
		else:
			break
	return (li[0][0], anss)
for i in range(int(input())):
	n = int(input())
	arr = input()
	temp = calc(arr)
	print(temp[0])
	print(temp[1])


def operat(s, k):
	res = list(s)
	for i in range(len(res) - k + 1):
		res[i:i + k] = reversed(res[i:i + k])
	print(''.join(res))
t = int(input())
while t > 0:
	n = int(input())
	s = input()
	current = s
	original = s
	k = 1
	for i in range(1, n):
		if (n - i) % 2 == 0 and s[i:] + s[:i] < current:
			k = i + 1
			current = s[i:] + s[:i]
		if (n - i) % 2 == 1 and s[i:] + s[i - 1::-1] < current:
			k = i + 1
			current = s[i:] + s[i - 1::-1]
	print(current)
	print(k)
	t -= 1


from bisect import bisect_left
import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
from functools import cmp_to_key
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(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
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		n = iin()
		s = sin()
		x = min(s)
		idx = -1
		mini = ''
		for i in range(n):
			tmp = ''
			if s[i] == x:
				ll = len(s[i:])
				if ll % 2 == 0:
					tmp = s[i:] + s[:i]
				else:
					tmp = s[i:] + s[:i][::-1]
				if mini == '':
					mini = tmp
					idx = i
				elif mini > tmp:
					mini = tmp
					idx = i
		print(mini)
		print(idx + 1)
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())

def op(s, k):
	s2 = list(s)
	if k < len(s):
		s3 = s2[k - 1:]
		s4 = s2[0:k - 1]
		if len(s3) % 2 != 0:
			s2 = s3 + s4[::-1]
		else:
			s2 = s3 + s4
		return ''.join([e for e in s2])
	else:
		return ''.join([e for e in s2[::-1]])
for i in range(t):
	n = int(input())
	s = input()
	s1 = s
	k1 = 1
	for k in range(1, len(s) + 1):
		if s[k - 1] <= s[0]:
			if op(s, k) < s1:
				s1 = op(s, k)
				k1 = k
	print(s1)
	print(k1)


t = int(input())
for loop in range(t):
	n = int(input())
	s = input()
	lis = []
	for k in range(1, n + 1):
		temp = list(s[:k - 1])
		if (n - k + 1) % 2 == 1:
			temp.reverse()
		ns = s[k - 1:] + ''.join(temp)
		lis.append([ns, k])
	lis.sort()
	print(lis[0][0])
	print(lis[0][1])


from collections import deque
for _ in range(int(input())):
	n = int(input())
	s = input()
	l1 = []
	c = 1
	s1 = ''
	fg = 0
	l1.append(s)
	if n % 2 == 0:
		fg = 1
	if fg == 0:
		for i in range(1, n):
			if i % 2 == 0:
				s1 += s[c:n] + s[c - 1:0:-1] + s[0]
				l1.append(s1)
				s1 = ''
				c += 1
			else:
				s1 += s[c:n] + s[0:c]
				l1.append(s1)
				s1 = ''
				c += 1
	else:
		for i in range(1, n):
			if i % 2 != 0:
				s1 += s[c:n] + s[c - 1:0:-1] + s[0]
				l1.append(s1)
				s1 = ''
				c += 1
			else:
				s1 += s[c:n] + s[0:c]
				l1.append(s1)
				s1 = ''
				c += 1
	l2 = sorted(l1)
	print(l2[0])
	print(l1.index(l2[0]) + 1)


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

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

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

def liststr():
	return list(map(str, input().strip().split()))

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	x // d if x % d == 0 else x // d + 1

def LCM(a, b):
	return a * b // gcd(a, b)

def solve():
	n = iin()
	a = sin()
	z = []
	for k in range(n - 1):
		if n % 2 == k % 2:
			z.append([a[k:] + a[:k], k + 1])
			continue
		z.append([a[k:] + a[:k][::-1], k + 1])
	z.append([a[::-1], n])
	for i in min(z):
		print(i)
t = 1
t = int(input())
for hula in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	s = ' ' + s
	L = list(s)
	m = min(L[1:])
	p = L[1:].count(m)
	if p == n:
		print(s[1:])
		print('1')
	else:
		k = 0
		f = ''
		k = L[k + 1:].index(m)
		k += 1
		te = L[1:k]
		if (n - k) % 2 != 0:
			Li = L[k:] + te
		else:
			te.reverse()
			Li = L[k:] + te
		f = ''.join(Li)
		ki = k
		p -= 1
		while p != 0:
			k += L[k + 1:].index(m)
			k += 1
			te = L[1:k]
			if (n - k) % 2 != 0:
				Li = L[k:] + te
			else:
				te.reverse()
				Li = L[k:] + te
			x = ''.join(Li)
			if f > x:
				f = x
				ki = k
			p -= 1
		print(f)
		print(ki)


from sys import stdin, stdout
from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	s = stdin.readline().rstrip('\n')
	s1 = s
	a = min(s)
	l = []
	d = defaultdict(list)
	for j in range(n):
		if s[j] == a:
			l.append(j)
	for j in l:
		if (n - j) % 2 != 0:
			s2 = s[j:] + s[:j][::-1]
		else:
			s2 = s[j:] + s[:j]
		if s2 <= s1:
			k = j + 1
			s1 = s2
			d[s1].append(k)
	stdout.write(s1 + '\n')
	print(min(d[s1]))


t = int(input())
for k in range(t):
	n = int(input())
	aString = input()
	aStringRev = aString[::-1]
	a = []
	for i in range(n):
		if (n - i) % 2 == 0:
			a.append(aString[i:n] + aString[0:i])
		else:
			a.append(aString[i:n] + aStringRev[n - i:n])
	minStrID = 0
	for i in range(n):
		if a[i] < a[minStrID]:
			minStrID = i
	print(a[minStrID] + '\n' + str(minStrID + 1))


def main():
	for _ in range(int(input())):
		n = int(input())
		s = list(input())
		k = 1
		ans = s
		for i in range(2, n + 1):
			if (n - i - 1) % 2 == 1 and s[i - 1:n] + s[i - 2::-1] < ans:
				k = i
				ans = s[i - 1:n] + s[i - 2::-1]
			elif (n - i - 1) % 2 == 0 and s[i - 1:n] + s[0:i - 1] < ans:
				k = i
				ans = s[i - 1:n] + s[0:i - 1]
		print(''.join(ans))
		print(k)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	a = []
	for i in range(1, n + 1):
		if i % 2 == 0:
			k = s[:n - i]
		else:
			d = s[:n - i]
			k = d[::-1]
		a.append((s[-i:] + k, i))
	a.sort()
	i = a[0][1]
	if n > 1 and a[0][0] == a[1][0]:
		i = max(a[0][1], a[1][1])
		k = a[0][0]
		j = 2
		while j < n and a[j][0] == k:
			i = max(i, a[j][1])
			j += 1
	print(a[0][0])
	print(n + 1 - i)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = []
	for k in range(0, n + 1):
		l.append((s[k:] + (s[:k] if (n - k) % 2 == 0 else s[:k][::-1]), k))
	l.sort()
	print(l[0][0])
	print(l[0][1] + 1)


t = int(input())
for i in range(0, t, 1):
	n = int(input())
	s = input()
	best = s[0:n]
	bestk = 1
	for i in range(2, n + 1, 1):
		result = ''
		if n % 2 != i % 2:
			result = result + s[i - 1:n] + s[0:i - 1]
		else:
			result = result + s[i - 1:n] + s[0:i - 1][::-1]
		if result < best:
			best = result
			bestk = i
	print(best)
	print(bestk)


t = int(input())
for s in range(t):
	n = int(input())
	s = input()
	cnt = 1
	rs = s
	for i in range(2, n + 1):
		if (n - i) % 2 == 1:
			r = s[i - 1:] + s[:i - 1]
		else:
			r = s[i - 1:] + s[:i - 1][::-1]
		if rs > r:
			rs = r
			cnt = i
	print(rs)
	print(cnt)


t = int(input())
for _ in range(t):
	l = int(input())
	s = input()
	ans = s
	ansl = 1
	for i in range(l):
		ns = s[i:] + s[:i][::-1 if l - i & 1 else 1]
		if ns < ans:
			ans = ns
			ansl = i + 1
	print(ans)
	print(ansl)


import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations, accumulate, combinations, product
from fractions import gcd

def input():
	return sys.stdin.readline()[:-1]

def ruiseki(lst):
	return [0] + list(accumulate(lst))
mod = pow(10, 9) + 7
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans0 = 'z' * 5000
	ans1 = 1
	for j in range(n):
		tmp = s
		if (j + n) % 2 == 1:
			tmp2 = s[j:] + s[:j][::-1]
		else:
			tmp2 = s[j:] + s[:j]
		if tmp2 < ans0:
			ans0 = tmp2
			ans1 = j + 1
	print(ans0)
	print(ans1)


def ii():
	return int(input())

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

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		n = ii()
		s = input()
		d = [0] * 26
		flag = 0
		f = 0
		x = []
		y = []
		pt = []
		ff = []
		r = []
		for i in range(n):
			d[ord(s[i]) - 97] = 1
		for i in range(26):
			if d[i] == 1:
				flag = i
				break
		for i in range(n):
			p = []
			q = []
			xs = ''
			ys = ''
			yr = ''
			vs = ''
			vr = ''
			if s[i] == chr(97 + flag):
				xs = s[i:]
				ys = s[:i]
				if (n - i) % 2 == 1:
					ys = ys[::-1]
				vr = xs + ys
				q.append(vr)
				q.append(i + 1)
			if len(p) != 0:
				y.append(p)
			if len(q) != 0:
				y.append(q)
			if vr != '':
				x.append(vr)
			if vs != '':
				x.append(vs)
		res = min((sub for sub in x if isinstance(sub, str)))
		for i in range(len(y)):
			if y[i][0] == res:
				pt.append(y[i][1])
		pt.sort()
		print(res)
		print(pt[0])
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	p = ''.join(sorted(s))
	x = p[0]
	ans = 0
	sample = 'z' * 100001
	for i in range(len(s)):
		S = s
		if S[i] == x:
			if (n - i) % 2 == 0:
				d = S[:i]
				if S[i:] + d < sample:
					sample = S[i:] + d
					ans = i + 1
			else:
				d = S[:i]
				if S[i:] + d[::-1] < sample:
					sample = S[i:] + d[::-1]
					ans = i + 1
	print(sample)
	print(ans)


T = int(input())

def compare(n, l, k, best):
	l1 = []
	l2 = []
	if (best + n) % 2 == 1:
		for i in range(n):
			l1.append(l[(best - 1 + i) % n])
	else:
		for i in range(best - 1, n):
			l1.append(l[i])
		for i in range(best - 2, -1, -1):
			l1.append(l[i])
	if (k + n) % 2 == 1:
		for i in range(n):
			l2.append(l[(k - 1 + i) % n])
	else:
		for i in range(k - 1, n):
			l2.append(l[i])
		for i in range(k - 2, -1, -1):
			l2.append(l[i])
	for i in range(n):
		if l1[i] < l2[i]:
			return (l1, best)
		elif l1[i] > l2[i]:
			return (l2, k)
	return (l1, best)
for _ in range(T):
	n = int(input())
	s = input()
	l = list(s)
	best = l.copy()
	bestk = 1
	for k in range(2, n + 1):
		(best, bestk) = compare(n, l, k, bestk)
	for i in range(n):
		print(best[i], end='')
	print()
	print(bestk)


def do(s, k):
	l = len(s)
	t = s
	k = k - 1
	if l % 2 == 0:
		if k % 2 == 0:
			return t[k:] + t[:k]
		else:
			return t[k:] + t[-l + k - 1:-l - 1:-1]
	elif k % 2 == 1:
		return t[k:] + t[:k]
	else:
		return t[k:] + t[-l + k - 1:-l - 1:-1]
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = list(s)
	res = []
	for i in range(1, n + 1):
		res.append((do(s, i), i))
	res.sort()
	print(res[0][0])
	print(res[0][1])


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 j in range(int(input())):
	n = int(input())
	vals = [ord(k) - 97 for k in input()]
	minsofar = vals.copy()
	minkey = 1
	for s in range(n):
		first = vals[0:s + 1]
		last = vals[s + 1:n]
		if (n - (s + 1)) % 2 == 1:
			first.reverse()
		tot = last + first
		for b in range(n):
			if tot[b] == minsofar[b]:
				continue
			else:
				if tot[b] < minsofar[b]:
					minsofar = tot
					minkey = s + 2
				break
	minsofar = [chr(k + 97) for k in minsofar]
	print(''.join(minsofar))
	print(minkey)


for u in range(int(input())):
	n = int(input())
	s = input()
	r = ''
	x = s
	c = 1
	for i in range(n):
		r = r + s[i:n]
		h = s[0:i]
		if (n - i) % 2 == 1:
			h = h[::-1]
		r = r + h
		if r < x:
			x = r
			c = 1 + i
		r = ''
	print(x)
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	ans = s
	a = 1
	for j in range(2, n + 1):
		tmp = s[j - 1:]
		if (n - j) % 2 == 1:
			tmp += s[:j - 1]
		else:
			tmp += s[j - 2::-1]
		if tmp < ans:
			ans = tmp
			a = j
	print(ans)
	print(a)


from collections import defaultdict
import math
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	string = input()
	ans = [[string, 1]]
	ans = [[string, 1]]
	for k in range(2, n + 1):
		new = string
		new = new[k - 1:] + new[:k - 1][::-1] if (n - k + 1) % 2 else new[k - 1:] + new[:k - 1]
		ans.append([new, k])
	print(*min(ans), sep='\n')


num = int(input())
for _ in range(num):
	n = int(input())
	s = input()
	ans = 0
	prev = s
	for k in range(n):
		ss = s[:k]
		if (n - k) % 2 == 1:
			ss = s[k:] + ss[::-1]
		else:
			ss = s[k:] + ss
		if prev > ss:
			prev = ss
			ans = k
	print(prev)
	print(ans + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ans = [(s, 1), (s[::-1], n)]
	for i in range(2, n):
		if (n - i + 1) % 2:
			x = ''.join((s[i - 1:], s[i - 2::-1]))
			ans.append((x, i))
		else:
			x = ''.join((s[i - 1:], s[:i - 1]))
			ans.append((x, i))
	ans.sort()
	print(*ans[0], sep='\n')


for _ in range(int(input())):
	n = int(input())
	string = input()
	smallest = 'z'
	for i in range(0, n):
		if string[i] < smallest:
			smallest = string[i]
	indexes = []
	for i in range(0, n):
		if string[i] == smallest:
			indexes.append(i + 1)
	options = []
	for index in indexes:
		rev = string[:index - 1]
		ns = None
		if (n - index - 1) % 2 == 0:
			ns = string[index - 1:] + rev
		else:
			ns = string[index - 1:] + rev[::-1]
		options.append((ns, index))
	(ns, index) = min(options)
	print(ns)
	print(index)


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	n = inp()
	s = insr()
	a = list(s)
	q = len(a) % 2
	qw = ['zz']
	for i in range(len(a)):
		if q ^ i % 2:
			w = list(reversed(a[:i]))
		else:
			w = a[:i]
		if qw > a[i:] + w:
			qw = a[i:] + w
			qwqw = i + 1
	print(''.join(qw))
	print(qwqw)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = []
	for k in range(1, n + 1):
		if (n - k) % 2 == 1:
			l.append((s[k - 1:] + s[:k - 1], k))
		else:
			l.append((s[k - 1:] + s[:k - 1][::-1], k))
	ans = min(l)
	print(ans[0])
	print(ans[1])


import sys
import copy
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(input().rstrip())
	d = a.index(min(a)) + 1
	p = []
	for i in range(n):
		if a[i] == min(a):
			p.append(i)
	r = ['z' for i in range(n)]
	for i in p:
		if i == n - 1:
			s = a[::-1]
		elif (n - i) % 2 == 0 or i == 0:
			s = a[i:] + a[:i]
		else:
			s = a[i:] + a[:i][::-1]
		if s < r:
			r = s
			d = i + 1
	print(''.join(r))
	print(d)


for tc in range(int(input())):
	n = int(input())
	s = input()
	ar = [0] * (n + 1)
	v = list(s)
	for i in range(n):
		v[i] = ord(s[i]) - 97
	d = min(v)
	g = v.index(d)
	ans = []
	for i in range(n):
		if v[i] == d:
			ans.append(i)
	an = []
	for i in ans:
		if (n - i) % 2 != 0:
			an.append(([s[i:] + s[:i][::-1]], i + 1))
		else:
			an.append(([s[i:] + s[:i]], i + 1))
	an.sort()
	print(*an[0][0])
	print(an[0][1])


q = int(input())
for _ in range(q):
	n = int(input())
	s = input()
	a = 1
	t = s
	for i in range(1, n):
		x = s[i:]
		if n - i & 1:
			x += s[i - 1::-1]
		else:
			x += s[:i]
		if x < t:
			t = x
			a = i + 1
	print(t)
	print(a)


def rev(s):
	t = ''
	q = len(s)
	for i in range(q):
		t += s[q - 1 - i]
	return t
t = int(input())
a = []
for i in range(t):
	n = input()
	a.append(input())
for s in a:
	k = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
	for j in range(0, len(s)):
		h = len(s) - j
		m = ''
		if h % 2 == 0:
			m = s[j:len(s)] + s[0:j]
		else:
			m = s[j:len(s)] + rev(s[0:j])
		if m < k:
			k = m
			q = j
	print(k)
	print(q + 1)


import sys

def gs(s, k):
	n = len(s)
	return s[k - 1:] + (s[:k - 1] if (n - k) % 2 == 1 else s[:k - 1][::-1])
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline().strip()
	km = min(range(1, n + 1), key=lambda k: gs(s, k))
	print(gs(s, km))
	print(km)


tc = int(input())
for _ in range(tc):
	n = int(input())
	s = str(input())
	ans = s
	op = 0
	for k in range(1, n):
		t = ''
		if n % 2 != k % 2:
			t = s[k:] + s[0:k][::-1]
		else:
			t = s[k:] + s[0:k]
		if t < ans:
			ans = t
			op = k
	print(ans)
	print(op + 1)


kl = int(input())
for l in range(kl):
	n = int(input())
	s = str(input())
	al = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(26):
		if s.find(al[i]) != -1:
			f = al[i]
			break
	k = s.find(f)
	ind = []
	while k != -1:
		ind = ind + [k]
		k = s.find(f, k + 1)
		sat = s
		km = ind[0] + 1
		sm = s
	for i in range(len(ind)):
		k = ind[i]
		s = sat
		sp = s[:k]
		if (n - k) % 2 != 0:
			sp = sp[::-1]
		s = s[k:] + sp
		if s < sm:
			km = k + 1
			sm = s
	print(sm)
	print(km)


import sys

def input():
	return sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	s = input()
	arr = []
	for k in range(0, n):
		if n % 2 == 0:
			if k % 2 == 1:
				ns = s[k:] + s[:k][::-1]
			else:
				ns = s[k:] + s[:k]
		elif k % 2 == 0:
			ns = s[k:] + s[:k][::-1]
		else:
			ns = s[k:] + s[:k]
		arr.append((ns, k + 1))
	arr.sort(key=lambda x: x[0])
	print(arr[0][0])
	print(arr[0][1])


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	min_str = s
	k = s
	ans = 1
	for j in range(2, n + 1):
		if (n - j) % 2 != 0:
			k = s[j - 1:] + s[:j - 1]
		else:
			x = s[:j - 1]
			k = s[j - 1:] + x[j - 2::-1]
		if k < min_str:
			min_str = k
			ans = j
	print(min_str)
	print(ans)


import copy
for _ in range(int(input())):
	n = int(input())
	s = input()
	ar = list(s)
	ch = s
	k = 1
	for i in range(1, n):
		a = s[:i]
		b = s[i:]
		if i % 2 != n % 2:
			a = a[::-1]
		c = b + a
		if c < ch:
			ch = c
			k = i + 1
	print(ch)
	print(k)


for __ in range(int(input())):
	n = int(input())
	ans = s = ' ' + input()
	k = 1
	for i in range(2, n + 1):
		if n - i + 1 & 1 == 1:
			t = ' ' + s[i:n + 1] + s[i - 1:0:-1]
		else:
			t = ' ' + s[i:n + 1] + s[1:i]
		if t < ans:
			ans = t
			k = i
	print(ans[1:n + 1])
	print(k)


t = int(input())
for nt in range(t):
	n = int(input())
	s = input()
	mr = s
	bk = 1
	for k in range(2, n + 1):
		p = s[k - 1:] + (s[:k - 1] if (n - k) % 2 else s[:k - 1][::-1])
		if p < mr:
			mr = min(s, p)
			bk = k
	print(mr)
	print(bk)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def Golf():
	(*a,) = map(int, open(0))

def S_():
	return input()

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

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

def I():
	return int(input())

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

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}):
	mp = [1] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [1] + [mp_def[j] for j in s] + [1]
	mp += [1] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
t = I()
for _ in range(t):
	n = I()
	s = input()
	st = []
	for i in range(n):
		x = n - (i + 1) + 1
		st.append((s[i:] + s[:i][::1 - 2 * (x % 2)], i + 1))
	(t, k) = sorted(st)[0]
	print(t)
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	mini = min(s)
	ans = s
	ind = 0
	for i in range(n):
		if s[i] == mini:
			temp = s[i:]
			if (n - i) % 2 != 0:
				temp += s[i - 1::-1]
			else:
				temp += s[:i]
			if temp < ans:
				ans = temp
				ind = i
	print(ans)
	print(ind + 1)


inf = int(10000000000.0)
t = int(input())
for _ in range(t):
	n = int(input())
	lis = input()
	if n == 1:
		print(lis)
		print(1)
	else:
		m = min(lis)
		index = []
		for i in range(n):
			if lis[i] == m:
				index.append(i)
		z = 'z' * n
		maxx = inf
		for i in range(n + 1):
			if (n + i) % 2 == 0:
				s1 = lis[i:] + lis[:i]
			else:
				s1 = lis[i:] + lis[:i][::-1]
			if s1 < z:
				maxx = i
				z = s1
		print(z)
		print(maxx + 1)


t = input()
for i in range(int(t)):
	length = int(input())
	line = input()
	temp = ''.join(line)
	minn = ''.join(line)
	m = 1
	for k in range(2, length):
		if (length - k) % 2 == 0 and k != 2:
			tem1 = line[k - 1:]
			tem2 = line[0:k - 1]
			tem3 = tem2[::-1]
			temp = tem1 + tem3
			if temp < minn:
				minn = ''.join(temp)
				m = k
			continue
		tem1 = line[k - 1:]
		tem2 = line[0:k - 1]
		temp = tem1 + tem2
		if temp < minn:
			minn = ''.join(temp)
			m = k
	temp = line[::-1]
	if temp < minn:
		minn = ''.join(temp)
		m = length
	print(minn)
	print(m)


def main():
	t = int(input())
	while t:
		t -= 1
		n = input()
		s = input()
		ans = s
		an = 1
		for i in range(len(s)):
			temp = s[i:]
			temp1 = s[:i]
			if len(s) - i & 1:
				temp += temp1[::-1]
			else:
				temp += temp1
			if temp < ans:
				ans = temp
				an = i + 1
		print(ans)
		print(an)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	test = s
	kavi = 1
	for i in range(1, n):
		if i & 1 == n & 1:
			temp = s[i:] + s[0:i]
		else:
			temp = s[i:] + s[0:i][::-1]
		if temp < test:
			test = temp
			kavi = i + 1
	print(test)
	print(kavi)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def main():
	try:
		n = I()
		s = input()
		mi = s
		ans = 1
		for i in range(n + 1):
			p = s
			temp = p[0:i]
			if n - i + 1 & 1 != 1:
				temp = temp[::-1]
			p = p[i:n] + temp
			if p < mi:
				mi = p
				ans = i + 1
		print(mi)
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
t = iinput()
for _ in range(t):
	n = iinput()
	s = input()
	l = []
	for k in range(0, n + 1):
		l.append((s[k:] + (s[:k] if (n - k) % 2 == 0 else s[:k][::-1]), k))
	l.sort()
	print(l[0][0])
	print(l[0][1] + 1)


import heapq
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	s = input().strip()
	ansq = []
	for i in range(n):
		if i == 0:
			heapq.heappush(ansq, (s[:], 1))
		else:
			heapq.heappush(ansq, (s[i:n] + (s[:i] if (n - i) % 2 == 0 else s[i - 1::-1]), i + 1))
	(ans_s, ans_i) = heapq.heappop(ansq)
	print(ans_s)
	print(ans_i)


from sys import stdin, stdout
input = stdin.readline
for _ in ' ' * int(input()):
	n = int(input())
	s = list(input())[:-1]
	ans = list(s)
	ind = 0
	for k in range(n):
		if (n - k) % 2:
			st = s[k:] + s[:k][::-1]
		else:
			st = s[k:] + s[:k]
		if st < ans:
			ind = k
			ans = list(st)
	print(''.join(ans))
	print(ind + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = []
	for i in range(n):
		if (n - (i + 1) + 1) % 2 != 0:
			s1 = s[i:n] + s[:i][::-1]
			l.append([s1, i + 1])
		else:
			s1 = s[i:n] + s[:i]
			l.append([s1, i + 1])
	l.sort(key=lambda x: x[0])
	print(l[0][0])
	print(l[0][1])


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	if len(set(s)) == 1:
		print(s)
		print(1)
		continue
	s = ' ' + s
	(ans, ansk) = (s, 1)
	for k in range(2, n + 1):
		st = ' ' + s[k:] + (s[1:k] if n % 2 != k % 2 else s[1:k][::-1])
		if st == ans and (k < ansk or ansk == 0) or st < ans:
			ans = st
			ansk = k
	print(ans[1:])
	print(ansk)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	a = []
	for i in range(n):
		if i == n - 1:
			a.append([s[::-1], i + 1])
			continue
		if (n - i) % 2 == 0:
			l = s[i:n] + s[0:i]
		elif i == 0:
			l = s
		else:
			l = s[i:n] + s[i - 1::-1]
		a.append([l, i + 1])
	a.sort(key=lambda x: x[0])
	k = a[0][1]
	for i in range(1, n):
		if a[i][0] == a[i][1]:
			if k > a[i][1]:
				k = a[i][1]
		else:
			break
	print(a[0][0])
	print(k)
	t -= 1


import bisect
from queue import Queue

def flipper(s, start, end):
	l = [s[x] for x in range(end, start - 1, -1)]
	index = 0
	for i in range(start, end + 1):
		s[i] = l[index]
		index += 1
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	t = [s[i] for i in range(len(s))]
	bestIndex = 0
	bestVal = s[0]
	indexCandidate = []
	for i in range(1, n):
		if s[i] < bestVal:
			bestIndex = i
			bestVal = s[i]
		elif s[i] == bestVal:
			k = 1
			if i != n - 1:
				while i + k < n and bestIndex + k < n and (s[i + k] == s[bestIndex + k]):
					k += 1
				if i + k >= n or bestIndex + k >= n:
					indexCandidate.append(bestIndex)
					bestIndex = i
					bestVal = s[i]
					continue
				if s[i + k] < s[bestIndex + k]:
					bestIndex = i
					bestVal = s[i]
			else:
				while i - k >= 0 and bestIndex + k < n and (s[i - k] == s[bestIndex + k]):
					k += 1
				if i - k < 0 or bestIndex + k >= n:
					indexCandidate.append(bestIndex)
					bestIndex = i
					bestVal = s[i]
					continue
				if s[i - k] < s[bestIndex + k]:
					bestIndex = i
					bestVal = s[i]
	for i in range(0, n - bestIndex):
		s = flipper(s, i, i + bestIndex)
	best = ''.join(s)
	for bindex in indexCandidate:
		s = [t[i] for i in range(n)]
		for i in range(0, n - bindex):
			s = flipper(s, i, i + bindex)
		st = ''.join(s)
		if st <= best:
			best = st
			bestIndex = bindex
			break
	print(best)
	print(f'{bestIndex + 1}')


for i in range(int(input())):
	n = int(input())
	string = input()
	k = 1
	ans = string
	for it in range(2, n + 1):
		prefix = string[it - 1:]
		suffix = string[:it - 1]
		if n % 2 == it % 2:
			suffix = suffix[::-1]
		word = prefix + suffix
		if ans > word:
			ans = word
			k = it
	print(ans)
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if len(s) == 1:
		print(s)
		print(1)
		continue
	res = []
	for k in range(0, n):
		ss = s
		if (n - k) % 2 == 1:
			ss = ss[k:] + ss[:k][::-1]
		else:
			ss = ss[k:] + ss[:k]
		res.append((ss, k + 1))
	res.sort()
	print(res[0][0])
	print(res[0][1])


t = int(input())
for i in range(t):
	n = int(input())
	stri = [i for i in input()]
	z = ['z'] * 50002
	count = 0
	if n % 2 == 1:
		for i in range(1, n + 1):
			if i % 2 == 0:
				s = stri[i - 1:] + stri[:i - 1]
				if s < z:
					z = s
					count = i
			else:
				s = stri[i - 1:n] + stri[0:i - 1][::-1]
				if s < z:
					z = s
					count = i
	else:
		for i in range(1, n + 1):
			if i % 2 == 1:
				s = stri[i - 1:] + stri[:i - 1]
				if s < z:
					z = s
					count = i
			else:
				s = stri[i - 1:n] + stri[0:i - 1][::-1]
				if s < z:
					z = s
					count = i
	print(''.join(z))
	print(count)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	maxi = s[0:n]
	ind = 0
	for i in range(n):
		curr = s[i:n]
		if (n - i) % 2 == 0:
			curr = curr + s[0:i]
		else:
			curr = curr + s[i - 1::-1]
		if curr < maxi:
			maxi = curr
			ind = i
	print(maxi)
	print(ind + 1)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	s = input()
	s = s[:-1]
	ans = 0
	mina = s
	for i in range(n):
		pref = s[:i]
		suff = s[i:]
		swaps = n - i
		if swaps % 2:
			z = suff + pref[::-1]
		else:
			z = suff + pref
		if z < mina:
			mina = z
			ans = i
	print(mina)
	print(ans + 1)


from functools import reduce

def flip(s, k):
	return s[k:] + s[:k][::-1 if len(s) % 2 != k % 2 else 1]

def cmp(pL, pR):
	return pR if pR[1] < pL[1] else pL
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = reduce(cmp, map(lambda k: (k + 1, flip(s, k)), range(n)))
	print(ans[1])
	print(ans[0])


def check(k, st):
	n = len(st)
	if (n - k + 1) % 2 == 0:
		return st[k - 1:n:1] + st[0:k - 1:1]
	else:
		return st[k - 1:n:1] + st[k - 2::-1]

def process(n, st):
	s = st
	result = 1
	for k in range(1, n + 1):
		kq = check(k, st)
		if kq < s:
			s = kq
			result = k
	print(s)
	print(result)
t = int(input())
for i in range(0, t):
	n = int(input())
	st = input()
	process(n, st)


def compare(x):
	return x[0]
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		print(1)
		continue
	arr = []
	for i in range(n):
		tmp = ''
		if (n - i) % 2 == 0 or i == 0:
			tmp = s[i:n] + s[0:i]
		else:
			tmp = s[i:n] + s[i - 1::-1]
		arr.append([tmp, i])
	arr.sort(key=compare)
	print(arr[0][0])
	k = arr[0][1] + 1
	for i in range(n):
		if arr[0][0] == arr[i][0]:
			k = min(k, arr[i][1] + 1)
	print(k)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	s = input()
	a = 0
	for i in range(1, n):
		if s[a:] + s[:a][::-1 if (n - a) % 2 == 1 else 1] > s[i:] + s[:i][::-1 if (n - i) % 2 == 1 else 1]:
			a = i
	print(f'{s[a:] + s[:a][::-1 if (n - a) % 2 == 1 else 1]}\n{a + 1}')


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline()[:-1]
	ans = s
	k = 1
	for i in range(1, n):
		if (n - i) % 2 == 0:
			if s[i:] + s[:i] < ans:
				ans = s[i:] + s[:i]
				k = i + 1
		elif s[i:] + s[i - 1::-1] < ans:
			ans = s[i:] + s[i - 1::-1]
			k = i + 1
	stdout.write(ans + '\n' + str(k) + '\n')


import string
from sys import stdin
input = stdin.readline
read = lambda : map(lambda s: int(s), input().strip().split())
readi = lambda : int(input())
from collections import defaultdict, Counter
from bisect import bisect_left as bl, bisect_right as br
from random import randint
from math import gcd, ceil
RANDOM = randint(1, 10 ** 9)

class Wrapper(int):

	def __hash__(self):
		return super(Wrapper, self).__hash__() ^ RANDOM

def gen(s, k):
	i = 0
	if (len(s) - k) % 2 == 0:
		return s[k:] + s[:k]
	else:
		return s[k:] + s[:k][::-1]
	return s
for _ in range(readi()):
	n = readi()
	s = input().strip()
	if n == 1:
		print(s, 1, sep='\n')
		continue
	ind = []
	mn = min(s)
	for (id, i) in enumerate(s):
		if i == mn:
			ind.append(id)
	ans = 'z' * n
	k = None
	for i in ind:
		t = gen(s, i)
		if t < ans:
			ans = t
			k = i
	print(ans, k + 1, sep='\n')


t = int(input())

def getIndexPositions(listOfElements, element):
	indexPosList = []
	indexPos = 0
	while True:
		try:
			indexPos = listOfElements.index(element, indexPos)
			indexPosList.append(indexPos)
			indexPos += 1
		except ValueError as e:
			break
	return indexPosList
for i in range(0, t):
	n = int(input())
	s = input()
	a = min(s)
	l = list(s)
	n = len(l)
	index = getIndexPositions(l, a)
	b = s
	x = 0
	for i in range(0, len(index)):
		s1 = s[index[i]:]
		if (n - index[i]) % 2 == 0:
			s1 = s1 + s[0:index[i]]
		else:
			s1 = s1 + s[index[i] - 1::-1]
		if s1 < b:
			b = s1
			x = index[i]
	print(b)
	print(x + 1)


testCases = int(input())
for i1 in range(testCases):
	length = int(input())
	sequence = input()
	ans = 1
	result = sequence
	for k in range(length):
		if k % 2 == length % 2:
			new = sequence[k:] + sequence[0:k]
		else:
			new = sequence[k:] + sequence[0:k][::-1]
		if new < result:
			result = new
			ans = k + 1
	print(result)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = s
	k = 1
	for i in range(2, n + 1, 1):
		if (n - i) % 2 == 0:
			z = s[i - 1:] + s[:i - 1][::-1]
			if z < ans:
				ans = z
				k = i
		else:
			z = s[i - 1:] + s[:i - 1]
			if z < ans:
				ans = z
				k = i
	print(ans)
	print(k)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(s, n):
	s = list(s)
	record = defaultdict(list)
	for k in range(n):
		new_k = n - k + 1
		if new_k % 2 == 0:
			ss = s[k:] + s[:k][::-1]
		else:
			ss = s[k:] + s[:k]
		record[''.join(ss)].append(k + 1)
	min_s = min(record.keys())
	print(min_s)
	print(record[min_s][0])

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		solution(s, n)
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


from math import *
test = int(input())
for y in range(test):
	n = int(input())
	s = input()
	ans = s
	k = 1
	for i in range(1, n + 1):
		if i % 2 != n % 2:
			t = s[i:] + s[:i][::-1]
		else:
			t = s[i:] + s[:i]
		if t < ans:
			ans = t
			k = i + 1
	print(ans)
	print(k)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = ''
	ansk = -1
	for k in range(1, n + 1):
		hilu = s[:k - 1]
		if n % 2 == 0 and k % 2 == 0:
			hilu = hilu[::-1]
		if n % 2 != 0 and k % 2 != 0:
			hilu = hilu[::-1]
		yo = s[k - 1:] + hilu
		if ans == '':
			ans = yo
			ansk = k
		elif yo < ans:
			ans = yo
			ansk = k
	print(ans)
	print(ansk)


def checker(n, s):
	(ans1, ans2) = (1, s)
	for i in range(2, n + 1):
		k = s[i - 1:] + s[0:i - 1][::-1] if (n - i) % 2 == 0 else s[i - 1:] + s[0:i - 1]
		if k < ans2:
			(ans2, ans1) = (k, i)
	return (ans2, ans1)
for _ in range(int(input())):
	m = int(input())
	t = input()
	lst = checker(m, t)
	print(lst[0])
	print(lst[1])


def calc(s, x, y):
	ps = s[x:y:1]
	ss = s[0:x:1]
	if (y - x) % 2 != 0:
		ss = ss[::-1]
	sf = ps + ss
	return sf
for _ in range(int(input())):
	n = int(input())
	s = str(input())
	s1 = s
	k = 1
	for i in range(1, n + 1):
		ts = calc(s, i, n)
		if ts < s1:
			s1 = ts
			k = i + 1
	print(s1)
	print(k)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

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

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, S):
	ans = (S, 1)
	for i in range(2, N):
		j = i - 1
		if (len(S) - i) % 2 != 0:
			s = S[j:] + S[:j]
		else:
			s = S[j:] + S[j - 1::-1]
		if s < ans[0]:
			ans = (s, i)
	s = S[::-1]
	if s < ans[0]:
		ans = (s, N)
	return ans

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		S = read_str()
		print('%s\n%d' % slv(N, S))
main()


t = input()
for _ in range(int(t)):
	n = int(input())
	s = input()
	mn = 2000
	ind = []
	for i in range(n):
		if ord(s[i]) < mn:
			mn = ord(s[i])
			k = i + 1
	for i in range(n):
		if ord(s[i]) == mn:
			ind.append(i)
	ans = 'z' * n
	for i in range(len(ind)):
		j = ind[i] + 1
		if j == n:
			temp = s[::-1]
		elif n % 2 == 0 and j % 2 == 1 or (n % 2 == 1 and j % 2 == 0):
			temp = s[j - 1:] + s[0:j - 1]
		else:
			temp = s[j - 1:] + s[0:j - 1][::-1]
		if temp < ans:
			ans = temp
			k = j
	print(ans)
	print(k)


def main(n, s):
	res = 1
	res_s = s
	for k in range(1, n):
		st = s[k:] + s[k - 1::-1][::(-1) ** (n - k + 1)]
		if st < res_s:
			res_s = st
			res = k + 1
	return (res_s, res)
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	print(*main(n, s), sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	k = 1
	res = s[:]
	for i in range(1, n):
		n_res = s[i:]
		if n % 2 == i % 2:
			n_res += s[:i]
		else:
			n_res += s[i - 1::-1]
		if n_res < res:
			res = n_res[:]
			k = i + 1
	print(res)
	print(k)


for nt in range(int(input())):
	n = int(input())
	s = input()
	ans1 = 1
	ans2 = s
	for i in range(2, n + 1):
		if (n - i) % 2 == 0:
			k = s[i - 1:] + s[0:i - 1][::-1]
		else:
			k = s[i - 1:] + s[0:i - 1]
		if k < ans2:
			ans2 = k
			ans1 = i
	print(ans2)
	print(ans1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = str(input())
	X = []
	for k in range(1, n + 1):
		p = s[k - 1:]
		q = s[0:k - 1]
		if (n - k - 1) % 2 == 1:
			t = p + q[::-1]
		else:
			t = p + q
		X.append([t, k])
	X.sort()
	print(X[0][0])
	print(X[0][1])


t = int(input())

def modify(string, pos, ln):
	pr = string[pos - 1:ln]
	sf = string[0:pos - 1]
	if ln % 2 == pos % 2:
		sf = ''.join(reversed(sf))
	return pr + sf
for _ in range(t):
	n = int(input())
	s = input()
	ans = modify(s, 1, n)
	best = 1
	for k in range(2, n + 1):
		temp = modify(s, k, n)
		if temp < ans:
			ans = temp
			best = k
	print(ans)
	print(best)


for t in range(int(input())):
	n = int(input())
	s = input()
	(dic, se) = ({s: 1}, {s})
	for k in range(2, n):
		p = s[k - 1:] + (s[:k - 1], s[:k - 1][::-1])[n % 2 == k % 2]
		if p not in dic:
			dic[p] = k
			se.add(p)
	if s[::-1] not in dic:
		dic[s[::-1]] = n
		se.add(s[::-1])
	ans = min(se)
	print(ans)
	print(dic[ans])


T = int(input())
for i in range(T):
	t = int(input())
	s = input()
	if t == 1:
		print(s)
		print(1)
		continue
	mins = s[:]
	winner = 1
	for k in range(2, t):
		if (t - k) % 2 == 0:
			new = s[k - 1:] + s[k - 2::-1]
		else:
			new = s[k - 1:] + s[:k - 1]
		if new < mins:
			mins = new
			winner = k
	if s[::-1] < mins:
		print(s[::-1])
		print(t)
	else:
		print(mins)
		print(winner)


badStr = 'z' * 5005
for _ in range(int(input())):
	n = int(input())
	s = input()
	minStr = badStr
	minK = float('inf')
	for i in range(len(s)):
		ops = n - i
		currK = i + 1
		if ops % 2 == 1:
			new_str = s[i:] + s[:i][::-1]
		else:
			new_str = s[i:] + s[:i]
		if new_str < minStr:
			minStr = new_str
			minK = currK
	print(minStr)
	print(minK)


t = int(input())
for _ in range(t):
	n = int(input())
	s = [i for i in input()]
	pos = []
	if n % 2 == 0:
		for i in range(n - 1):
			if i % 2 == 0 and i > 1:
				pos.append([s[i:] + s[:i], i + 1])
			else:
				pos.append([s[i:] + s[:i][::-1], i + 1])
	else:
		for i in range(n - 1):
			if i % 2 != 0 and i > 1:
				pos.append([s[i:] + s[:i], i + 1])
			else:
				pos.append([s[i:] + s[:i][::-1], i + 1])
	pos.append([s[::-1], n])
	for i in range(n):
		pos[i][0] = ''.join(pos[i][0])
	pos.sort(key=lambda x: x[0])
	print(pos[0][0])
	print(pos[0][1])


def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
for i in range(ii()):
	n = ii()
	s = si()
	d = s
	ans = 1
	a = ''
	for i in range(n):
		a += s[i:n]
		b = s[0:i]
		if (n - i) % 2:
			b = b[::-1]
		a += b
		if a < d:
			d = a
			ans = i + 1
		a = ''
	print(d)
	print(ans)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def case():
	n = int(input())
	s = input().strip()
	ans = []
	for i in range(n):
		if (n - i) % 2 == 0:
			k = s[i:n] + s[0:i]
		else:
			k = s[i:n] + s[0:i][::-1]
		ans.append([k, i])
	ans.sort()
	print(''.join(map(str, ans[0][0])))
	print(ans[0][1] + 1)
for _ in range(int(input())):
	case()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	dic = {}
	ans = []
	for j in range(1, n + 1):
		if n % 2 == 0:
			if j % 2 != 0:
				a = s[j - 1:]
				b = s[:j - 1]
				s1 = a + b
				ans.append((s1, j))
			else:
				a = s[j - 1:]
				b = s[:j - 1][::-1]
				s1 = a + b
				ans.append((s1, j))
		elif j % 2 == 0:
			a = s[j - 1:]
			b = s[:j - 1]
			s1 = a + b
			ans.append((s1, j))
		else:
			a = s[j - 1:]
			b = s[:j - 1][::-1]
			s1 = a + b
			ans.append((s1, j))
	for j in ans:
		dic[j[0]] = []
	for j in ans:
		dic[j[0]].append(j[1])
	ans1 = []
	for j in ans:
		ans1.append(j[0])
	ans1.sort()
	ele = ans1[0]
	mi = min(dic[ele])
	print(ele)
	print(mi)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	for _ in range(int(input())):
		(n,) = aj()
		s = input()
		S = []
		S.append((s, 1))
		S.append((s[::-1], n))
		for i in range(2, n):
			if (n - i + 1) % 2:
				t = s[i - 1:] + s[:i - 1][::-1]
			else:
				t = s[i - 1:] + s[:i - 1]
			S.append((t, i))
		ans = min(S)
		print(ans[0])
		print(ans[1])
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


INF = 10 ** 10

def main():
	global mini, ans
	print = out.append
	n = get_int()
	st = input()
	mini = st
	ans = 1

	def pre(k):
		global mini, ans
		a = st[:k - 1]
		if (n - k + 1) % 2 != 0:
			a = a[::-1]
		s = st[k - 1:] + a
		if s < mini:
			ans = k
			mini = s
	[pre(i) for i in range(1, n + 1)]
	print(''.join(mini))
	print(ans)
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = min(s)
	minm = 'zzzzzzzzzzzzzzzzzzzzzzzzzzz'
	pos = 0
	res = ''
	for i in range(n):
		if s[i] == x:
			temp = s[i:n]
			if len(temp) % 2 == 0:
				res = temp + s[0:i]
			else:
				res = temp + s[0:i][::-1]
		if res != '' and res < minm:
			minm = res
			pos = i
	print(minm)
	print(pos + 1)


import sys
num_inputs = int(sys.stdin.readline())
k_min = 1

def modify(input, k):
	mid = input[0:k - 1]
	if (len(input) - k + 1) % 2 == 1:
		mid = mid[::-1]
	result = input[k - 1:] + mid
	return result

def LG_smaller(first, second):
	assert len(first) == len(second), 'length of two strings must be equal'
	if len(first) == 0:
		return True
	for position in range(len(first)):
		if first[position] != second[position]:
			if first[position] < second[position]:
				return True
			else:
				return False
for i in range(num_inputs):
	length = int(sys.stdin.readline())
	orig_string = sys.stdin.readline().split('\n')[0]
	for k in range(1, length + 1):
		if k == 1:
			k_min = 1
			smallest = modify(orig_string, k_min)
		else:
			modified = modify(orig_string, k)
			if modified < smallest:
				k_min = k
				smallest = modified
	print(smallest)
	print(k_min)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	res = (s, 1)
	for k in range(1, n + 1):
		pf = s[k - 1:]
		sf = ''
		if k % 2 == n % 2:
			sf = s[:k - 1][::-1]
		else:
			sf = s[:k - 1]
		c = pf + sf
		if (c, k) < res:
			res = (c, k)
	print(res[0])
	print(res[1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = 'z'
	for i in range(n):
		c = min(c, s[i])
	l = []
	for i in range(n):
		if s[i] == c:
			l.append(i)
	s1 = ''
	s2 = s[:]
	k = 0
	for i in l:
		s1 = s[i:]
		t = s[:i]
		if (n - i - 1) % 2 == 1:
			s1 += t
		else:
			s1 += t[::-1]
		if s1 < s2:
			s2 = s1
			k = i
	print(s2)
	print(k + 1)


t = eval(input())
for i in range(t):
	n = eval(input())
	st = input()
	min = 'z'
	for i in range(n):
		if st[i] < min:
			min = st[i]
	li = []
	for i in range(n):
		if st[i] == min:
			li = li + [i + 1]
	ans = st
	j = 1
	for k in li:
		temp = st[k - 1:]
		if len(temp) % 2 == 0:
			temp = temp + st[0:k - 1]
		else:
			stm = st[::-1]
			temp = temp + stm[-k + 1:]
		if temp < ans:
			ans = temp
			j = k
	print(ans)
	print(j)


def reverse(string):
	string = ''.join(reversed(string))
	return string

def f(s1, k):
	sr = ''
	sli = list(s1)
	for i in range(0, len(s1) - k + 1):
		s1 = s1[:i] + reverse(s1[i:i + k]) + s1[i + k:]
	return s1
for _ in range(0, int(input())):
	n = int(input())
	s = input()
	x = min(s)
	mini = []
	for i in range(0, len(s)):
		if s[i] == x:
			mini.append(i + 1)
	ms = s
	x = 1
	for i in range(0, len(mini)):
		k = mini[i]
		if (n - mini[i] + 1) % 2 != 0:
			res = s[k - 1:] + reverse(s[:k - 1])
		else:
			res = s[k - 1:] + s[:k - 1]
		if res < ms:
			ms = res
			x = mini[i]
	print(ms)
	print(x)


def f():
	n = int(input())
	a = input()
	mini = 'z' * 5001
	kp = 0
	for k in range(1, len(a) + 1):
		if (len(a) - k + 1) % 2 == 0:
			s = a[k - 1:len(a)] + a[0:k - 1]
			if s < mini:
				mini = s
				kp = k
		else:
			s = a[k - 1:len(a)] + a[0:k - 1][::-1]
			if s < mini:
				mini = s
				kp = k
	print(mini)
	print(kp)
for i in range(int(input())):
	f()


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def swap(s, i):
	num_moves = len(s) - i
	parity = (len(s) - i) % 2
	return s[i:] + (s[:i] if parity == 0 else s[:i][::-1])

def main():
	T = int(rl())
	numchar = lambda c: ord(c) - 97
	for _ in range(T):
		n = int(rl())
		s = rll()[0]
		(best, choices) = (min((numchar(c) for c in s)), [])
		for (i, c) in enumerate(s):
			num = numchar(c)
			if num <= best:
				best = num
				choices.append((swap(s, i), i))
		choices.sort()
		(ans, shift) = choices[0]
		stdout.write(str(ans))
		stdout.write('\n')
		stdout.write(str(shift + 1))
		stdout.write('\n')
	stdout.close()
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = min(s)
	k = []
	for i in range(n):
		if s[i] == x:
			k.append(i + 1)
	pos = []
	for kvalue in k:
		r = (n - kvalue + 1) % 2
		s2 = s[:kvalue - 1]
		if r:
			s2 = ''.join(reversed(s2))
		s1 = s[kvalue - 1:] + s2
		pos.append(s1)
	ans = min(pos)
	i = pos.index(ans)
	kans = k[i]
	print(ans)
	print(kans)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	x = min(s)
	c = []
	for i in range(n):
		if s[i] == x:
			c.append(i)
	q = 'zzzzzzzzzzzzzzzzzzzzzzzzzzz'
	m = 0
	for i in c:
		z = s[i:] + s[:i]
		y = s[i:] + s[:i][::-1]
		if (n - i) % 2 == 0:
			a = z
		else:
			a = y
		if q > a:
			q = a
			m = i
	print(q)
	print(m + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	assert len(s) == n

	def vasya(s, k):
		if (n - k) % 2 == 0:
			suffix = s[k - 2::-1]
		else:
			suffix = s[:k - 1]
		return s[k - 1:] + suffix
	best = (s, 1)
	for k in range(2, n + 1):
		v = (vasya(s, k), k)
		if v < best:
			best = v
	print(*best, sep='\n')


def solve(n, s):
	ans = s
	p = 1
	for i in range(n):
		flag = n - (i + 1)
		if flag % 2:
			t = s[i:] + s[:i]
		else:
			t = s[i:] + s[:i][::-1]
		if t < ans:
			ans = t
			p = i + 1
	print(ans)
	print(p)

def main():
	tc = int(input())
	for _ in range(tc):
		n = int(input())
		s = input()
		solve(n, s)
main()


for i in range(int(input())):
	n = int(input())
	s = str(input())
	t = s
	a = 1
	b = min(s)
	c = s.find(b)
	m = 1
	while c != -1:
		if c == 0:
			c = s.find(b, c + 1)
			continue
		if (n - c) % 2 != 0:
			s2 = s[c:] + s[0:c][::-1]
		else:
			s2 = s[c:] + s[0:c]
		if s2 < t:
			t = s2
			m = c + 1
		c = s.find(b, c + 1)
	print(t)
	print(m)


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	string = stdin.readline()[:-1]
	k = 1
	small_string = string
	for j in range(2, n + 1):
		if (n - j) % 2 == 0:
			cur_string = string[j - 1:] + string[:j - 1][::-1]
		else:
			cur_string = string[j - 1:] + string[:j - 1]
		if small_string > cur_string:
			small_string = cur_string
			k = j
	print(small_string)
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ls = min(s)
	i = s.find(ls)
	candidates = []
	while i != -1:
		if i == n - 1:
			candidates.append((s[::-1], n))
			break
		if (n - i) % 2 == 0:
			candidates.append((s[i:] + s[:i], i + 1))
		else:
			candidates.append((s[i:] + s[:i][::-1], i + 1))
		i = s.find(ls, i + 1)
	candidates.sort()
	print(candidates[0][0] + '\n' + str(candidates[0][1]))


T = int(input())
for _ in range(T):
	n = int(input())
	a = input()
	k = []
	s = a[0]
	for i in range(1, n):
		if a[i] < s:
			k = [i]
			s = a[i]
		elif a[i] == s:
			k.append(i)
	b = a
	s = b
	k1 = 1
	if n % 2 == 0:
		fo = 0
	else:
		fo = 1
	for i in k:
		if (i + 1) % 2 == 0 and fo == 0 or ((i + 1) % 2 != 0 and fo == 1):
			s = a[i:] + a[i - 1::-1]
			if s < b:
				b = s
				k1 = i + 1
		else:
			s = a[i:] + a[:i]
			if s < b:
				b = s
				k1 = i + 1
	print(b)
	print(k1)


T = int(input())
for test in range(T):
	n = int(input())
	lst = list(input())
	a = []
	a.append((''.join(lst), 1))
	for i in range(1, n):
		string = ''
		string += ''.join(lst[i:])
		if i % 2 == 0 and n % 2 == 1 or (i % 2 == 1 and n % 2 == 0):
			string += ''.join(list(reversed(lst[:i])))
		else:
			string += ''.join(lst[:i])
		a.append((string, i + 1))
	a.sort(key=lambda x: x[0])
	print(a[0][0])
	print(a[0][1])


t = int(input())
for tt in range(t):
	n = int(input())
	s = input()
	arr = []
	for i in range(n):
		if (n - i) % 2 == 0:
			x = s[i:] + s[0:i]
			arr.append((x, i + 1))
		else:
			x = s[i:] + s[0:i][::-1]
			arr.append((x, i + 1))
	x = s[::-1]
	arr.append((x, n))
	arr = sorted(arr, key=lambda x: x[0])
	print(arr[0][0])
	print(arr[0][1])


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input().rstrip()
		mi = s[:]
		l = 1
		for k in range(2, n + 1):
			z = s[k - 1:] + s[:k - 1][::-1] if n % 2 == k % 2 else s[k - 1:] + s[:k - 1]
			if mi > z:
				mi = z[:]
				l = k
		print(mi)
		print(l)
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')
main()


def solution(s, n, k):
	result_prefix = s[k - 1:n]
	result_suffix = s[0:k - 1]
	if n % 2 == k % 2:
		result_suffix = result_suffix[::-1]
	return result_prefix + result_suffix
for _ in range(int(input())):
	n = int(input())
	a = input()
	result = solution(a, n, 1)
	resulti = 1
	for l in range(1, n):
		temp = solution(a, n, l + 1)
		if temp < result:
			result = temp
			resulti = l + 1
	print(result)
	print(resulti)


def solve(inp):
	n = len(inp)
	mins = inp
	mink = 0
	for k in range(n):
		s1 = inp[k:]
		s2 = inp[0:k]
		if len(s1) % 2 != 0:
			s2 = s2[::-1]
		if s1 + s2 < mins:
			mins = s1 + s2
			mink = k
	return [mins, mink + 1]
t = int(input())
for i in range(t):
	n = input()
	s = input()
	ans = solve(s)
	print(ans[0])
	print(ans[1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	MAX = s
	ans = 1
	for i in range(n):
		tmp = s[0:i]
		now = s[i:n] + tmp[::(-1) ** (n - i)]
		if now < MAX:
			MAX = now
			ans = i + 1
	print(MAX)
	print(ans)


def krev(s, k):
	l = list(s)
	for i in range(len(s) - k + 1):
		l[i:i + k] = l[i:i + k][::-1]
	return ''.join(l)

def rrev(s, k):
	left = s[k - 1:]
	right = s[:k - 1]
	if len(s) % 2 == k % 2:
		right = right[::-1]
	return left + right

def solve(n, s):
	minc = min(s)
	I = [i for (i, c) in enumerate(s) if c == minc]
	return min(((rrev(s, i + 1), i + 1) for i in I))
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(w, k) = solve(n, s)
	print(w)
	print(k)


import sys
from math import log
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	n = II()
	s = list(SI())
	mn = min(s)
	ind = [i for i in range(n) if s[i] == mn]
	ans = {}
	val = {}
	for i in ind:
		x = ''.join(s[i:])
		if (n - i) % 2 and i > 0:
			x += ''.join(s[i - 1::-1])
		else:
			x += ''.join(s[:i])
		ans[i + 1] = x
		val[x] = min(i + 1, val.get(x, 10000000.0))
	mn = min(ans.values())
	print(mn, val[mn], sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	print(*min([(s[i:n] + (s[i - 1::-1] if i != 0 and (n - i) % 2 else s[:i]), i + 1) for i in range(n)]), sep='\n')


def go():
	n = int(input())
	s = input()
	cur = s
	curv = 1
	for k in range(2, n + 1):
		pref = s[:k - 1]
		if (n - k) % 2 == 0:
			pref = pref[::-1]
		cand = s[k - 1:] + pref
		if cand < cur:
			cur = cand
			curv = k
	return cur + '\n' + str(curv)
ans = []
t = int(input())
for _ in range(t):
	ans.append(go())
print('\n'.join(ans))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline().strip()
	ans = (str(s), 1)
	for k in range(2, n + 1):
		if (n - k + 1) % 2 == 0:
			sp = s[k - 1:] + s[:k - 1]
		else:
			sp = s[k - 1:] + s[:k - 1][::-1]
		if sp < ans[0]:
			ans = (sp, k)
	print(ans[0])
	print(ans[1])


cases = int(input())
for t in range(cases):
	n = int(input())
	s = input()
	s_ = s
	k = 1
	for i in range(1, n):
		if (i + 1 + n) % 2 == 0:
			s1 = s[i:] + s[:i][::-1]
		else:
			s1 = s[i:] + s[:i]
		if s1 < s_:
			s_ = s1
			k = i + 1
	print(s_)
	print(k)


t = int(input())
while t > 0:
	n = int(input())
	st = input()
	l = []
	l.append(st)
	for k in range(2, n + 1):
		if (n + 1 - k) % 2 != 0:
			s = st[k - 1:n] + st[0:k - 1][::-1]
			l.append(s)
		else:
			s = st[k - 1:n] + st[0:k - 1]
			l.append(s)
	p = l.copy()
	l.sort()
	print(l[0])
	print(p.index(l[0]) + 1)
	t -= 1


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		n = int(input())
		ss = input()
		res = 1
		best = ss

		def genstr(k):
			if (n - k) % 2 == 1:
				return ss[k:n] + ss[0:k][::-1]
			else:
				return ss[k:n] + ss[0:k]
		for k in range(2, n + 1):
			new = str(genstr(k - 1))
			if new < best:
				res = k
				best = new
		print(best)
		print(res)
	q = int(input())
	for _ in range(q):
		solve()
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def lexi(a, b):
	lenof = len(a)
	for i in range(lenof):
		if a[i] == b[i]:
			continue
		elif a[i] < b[i]:
			return True
		else:
			return False
	return False

def gift():
	for _ in range(t):
		n = int(input())
		string = input()
		loweststring = string[0]
		lowestpos = [0]
		for i in range(1, n):
			if ord(string[i]) < ord(loweststring):
				loweststring = string[i]
				lowestpos = [i]
			elif string[i] == loweststring:
				lowestpos.append(i)
		correstring = []
		nonrepeat = []
		for i in lowestpos:
			if i % 2 == (n - 1) % 2:
				tempstring = string[i:] + string[:i][::-1]
			else:
				tempstring = string[i:] + string[:i]
			if tempstring not in nonrepeat:
				nonrepeat.append(tempstring)
				correstring.append([tempstring, i + 1])
		(ans, ansinde) = correstring[0]
		lenans = len(correstring)
		for i in range(lenans - 1):
			if lexi(correstring[i + 1][0], ans):
				(ans, ansinde) = correstring[i + 1]
		yield ans
		yield ansinde
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	mi = min(s)
	l = []
	for i in range(n):
		if s[i] == mi:
			l.append(i)
	ans = []
	for i in l:
		if (n - i) % 2 == 1:
			st = ''
			st += s[i:] + s[0:i][::-1]
			ans.append([st, i])
		else:
			st = ''
			st += s[i:] + s[0:i]
			ans.append([st, i])
	ans.sort()
	print(ans[0][0])
	print(ans[0][1] + 1)


def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		k = 1
		ans = s
		for i in range(1, n + 1):
			if (len(s) - i + 1) % 2 == 0:
				t = s[i:] + s[:i][::-1]
			else:
				t = s[i:] + s[:i]
			if t < ans:
				ans = t
				k = i + 1
		t = s[::-1]
		if t < ans:
			ans = t
			k = n
		print(ans)
		print(k)
main()


import sys
print = sys.stdout.write
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	x = min(s)
	lis = []
	for i in range(n):
		if s[i] == x:
			lis.append(i)
	ss = s[:]
	k = 1
	for i in lis:
		l = []
		l.extend(s[i:])
		if i % 2 == n % 2:
			l.extend(s[:i])
		else:
			l.extend(s[:i][::-1])
		if ss > l:
			ss = l[:]
			k = i + 1
	print(''.join(ss) + '\n')
	print(str(k) + '\n')


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	In = 0
	ans = s
	an = 1
	for i in range(n):
		In = s.index(s[i], In)
		if (n - In) % 2 != 0:
			a = s[In:]
			b = s[:In]
			b = b[::-1]
			St = a + b
		else:
			St = s[In:] + s[:In]
		if St < ans:
			ans = St
			an = In + 1
		In += 1
	if an == n:
		ans = s[::-1]
	print(ans)
	print(an)


f = input
t = int(f())
for _ in [0] * t:
	(n, s) = (int(f()), f())
	print(*min(((s[k:] + s[:k][::1 - 2 * ((n - k) % 2)], k + 1) for k in range(n))), sep='\n')


def solve():
	n = int(input())
	st = str(input())
	minst = st
	ans = 0
	minchar = chr(ord('z') + 1)
	for i in range(0, n + 1):
		newst = st[i:] + str(st[0:i])[::-1 if (n - i + 1) % 2 == 0 else 1]
		if newst < minst:
			minst = newst
			ans = i
	print(minst)
	print(ans + 1)
T = int(input())
while T > 0:
	T -= 1
	solve()


def solve():
	n = int(input())
	s = input()
	best = None
	best_k = None
	for k in range(1, n + 1):
		pre = s[k - 1:]
		after = s[:k - 1]
		if (len(after) + n) % 2 == 1:
			after = after[::-1]
		current = pre + after
		if best is None or current < best:
			best = current
			best_k = k
	print(best)
	print(best_k)
n = int(input())
for _ in range(n):
	solve()


import sys
inp = sys.stdin.readline

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

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		s = list(input())
		ans = []
		for i in range(1, n + 1):
			x = i - 1
			y = n - x
			ans.append([''.join(s[x:] + (s[:x] if y % 2 == 0 else s[:x][::-1])), i])
		ans.sort()
		print(*ans[0], sep='\n')
main()


cases = int(input().strip())
for case in range(cases):
	n = int(input().strip())
	s = list(input().strip())
	options = []
	for k in range(1, n + 1):
		j = k - 1
		new_s = s[j:]
		if (n - k + 1) % 2 == 0:
			new_s += s[:j]
		else:
			new_s += reversed(s[:j])
		options.append((new_s, k))
	options = sorted(options)
	print(''.join(options[0][0]))
	print(options[0][1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	k = 1
	z = ''
	a = [s]
	b = []
	while k < n:
		z = s[k:n]
		if n % 2 == k % 2:
			z += s[0:k]
		else:
			z += s[0:k][::-1]
		a.append(z)
		b.append(k)
		k += 1
	print(min(a))
	try:
		print(b[a.index(min(a))])
	except IndexError:
		print(n)


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 10 ** 9 + 7
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = sys.stdin.readline()[:-1]
	l = [[0, 0] for x in range(n)]
	l[0][0] = s
	l[0][1] = 1
	for i in range(n):
		rem = n - i - 1
		if rem & 1 == 0:
			ns = s[i:] + s[:i][::-1]
			l[i - 1][0] = ns
			l[i - 1][1] = i + 1
		else:
			ns = s[i:] + s[:i]
			l[i - 1][0] = ns
			l[i - 1][1] = i + 1
	l.sort()
	print(l[0][0])
	print(l[0][1])


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input().strip()
	ans_k = 1
	ans = s
	for k in range(2, n + 1):
		res = s[k - 1:]
		if len(res) % 2 != 0:
			res += s[:k - 1][::-1]
		else:
			res += s[:k - 1]
		if res < ans:
			ans = res
			ans_k = k
	print(ans)
	print(ans_k)


def change(s, k):
	temp = len(s) - k
	if temp <= 0:
		return s[::-1]
	if (temp + 1) % 2 == 0:
		return s[k - 1:] + s[:k - 1]
	else:
		return s[k - 1:] + s[:k - 1][::-1]

def solve(s, n):
	l = {}
	for i in range(1, n + 1):
		t = change(s, i)
		if t not in l:
			l[t] = i
	ans = min(l)
	print(ans, l[ans], sep='\n')
T = int(input())
for i in range(T):
	n = int(input())
	s = input()
	solve(s, n)


for _ in range(int(input())):
	n = int(input())
	s = input()
	c = ''
	k = 0
	for i in range(n + 1):
		t = s[i:]
		if i % 2 != n % 2:
			t += s[:i][::-1]
		else:
			t += s[:i]
		if not c or t < c:
			c = t
			k = i
	print(c)
	print(k + 1)


t = int(input())
for j in range(t):
	n = int(input())
	s = input()
	S = s
	m = min(s)
	result = -1
	x = True
	l = []
	lst = []
	while x == True:
		result = s.find(m, result + 1)
		if result not in l and result != -1:
			l.append(result)
		else:
			break
	for k in l:
		first = ''
		second = ''
		if k > 0:
			if k % 2 == n % 2:
				first = s[0:k]
				second = s[k:]
				lst.append([second + first, k + 1])
			else:
				first = s[k - 1:0:-1] + s[0]
				second = s[k:]
				lst.append([second + first, k + 1])
		else:
			lst.append([s, k + 1])
	lst.sort(key=lambda x: x[0])
	print(lst[0][0])
	print(lst[0][1])


from sys import *
from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	x = []
	if n % 2 == 0:
		m = 1
	else:
		m = 0
	for k in range(1, n + 1):
		if (k - m) % 2 == 0:
			y = a[k - 1:] + a[:k - 1]
		else:
			y = a[k - 1:] + a[:k - 1][::-1]
		x.append(y)
	k = 1
	m = x[0]
	for i in range(1, n):
		for j in range(n):
			h = m[j]
			g = x[i][j]
			if m[j] > x[i][j]:
				k = i + 1
				m = x[i]
				break
			elif m[j] < x[i][j]:
				break
	print(m)
	print(k)


t = int(input())
for test in range(t):
	length = int(input())
	s = input()
	arr = [s]
	dicti = {}
	dicti[s] = 1
	for i in range(length - 1):
		x = s[:]
		if length % 2 == 0:
			if i % 2 == 1:
				x = x[i + 1:] + x[:i + 1]
				arr.append(x)
				if x not in dicti:
					dicti[x] = i + 2
			else:
				x = x[i + 1:] + x[i::-1]
				arr.append(x)
				if x not in dicti:
					dicti[x] = i + 2
		elif i % 2 == 0:
			x = x[i + 1:] + x[:i + 1]
			arr.append(x)
			if x not in dicti:
				dicti[x] = i + 2
		else:
			x = x[i + 1:] + x[i::-1]
			arr.append(x)
			if x not in dicti:
				dicti[x] = i + 2
	arr.sort()
	print(arr[0])
	print(dicti[arr[0]])


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		S = input().strip()
		ans = []
		for k in range(1, N + 1):
			tmp = S[:]
			if k == 1:
				pass
			elif (N + k) % 2 == 1:
				tmp = tmp[k - 1:] + tmp[:k - 1]
			else:
				tmp = tmp[k - 1:] + tmp[:k - 1][::-1]
			ans.append([tmp[:], k])
		ans.sort()
		print(ans[0][0])
		print(ans[0][1])
main()


for i in range(int(input())):
	n = int(input())
	s = input()
	mns = s
	ans = 1
	ss = []
	for m in range(1, n + 1):
		k = m - 1
		if (n - m + 1) % 2:
			if s[k:] + s[:k][::-1] < mns:
				mns = s[k:] + s[:k][::-1]
				ans = m
		elif mns > s[k:] + s[:k]:
			mns = s[k:] + s[:k]
			ans = m
	print(mns)
	print(ans)


import sys

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

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	s = input()
	mins = s[:]
	mink = 1
	for k in range(2, n + 1):
		if (n - k) % 2:
			ss = s[k - 1:n] + s[:k - 1]
		else:
			ss = s[k - 1:n] + s[:k - 1][::-1]
		if mins > ss:
			mink = k
			mins = ss[:]
	print(mins)
	print(mink)


for _ in range(int(input())):
	l = int(input())
	s = input()
	cmp = s
	res = s
	count = 1
	for i in range(2, l + 1):
		if l % 2 == i % 2:
			new = s[i - 1:] + s[:i - 1][::-1]
			if cmp > new:
				count = i
				res = new
				cmp = new
		else:
			new = s[i - 1:] + s[:i - 1]
			if cmp > new:
				count = i
				res = new
				cmp = new
	print(res)
	print(count)


def rds(s, n):
	mi = s
	a = 1
	if n % 2 == 0:
		for i in range(2, n + 1):
			if i % 2 == 0:
				qw = s[i - 1:] + s[:i - 1][::-1]
				if qw < mi:
					mi = qw
					a = i
			else:
				qw = s[i - 1:] + s[:i - 1]
				if qw < mi:
					mi = qw
					a = i
	else:
		for i in range(2, n + 1):
			if i % 2 != 0:
				qw = s[i - 1:] + s[:i - 1][::-1]
				if qw < mi:
					mi = qw
					a = i
			else:
				qw = s[i - 1:] + s[:i - 1]
				if qw < mi:
					mi = qw
					a = i
	return (mi, a)
for i in range(int(input())):
	n = int(input())
	s = input()
	(mi, a) = rds(s, n)
	print(mi)
	print(a)


for _ in range(int(input())):
	n = int(input())
	a = input()
	ind = 1
	ans = a
	for i in range(1, n + 1):
		if (n - i + 1) % 2 == 1:
			temp = a[i - 1:] + a[:i - 1][::-1]
		else:
			temp = a[i - 1:] + a[:i - 1]
		if temp < ans:
			ans = temp
			ind = i
	print(ans)
	print(ind)


import math
testCases = int(input())
for _ in range(testCases):
	n = int(input())
	s = input()
	allPosibilities = []
	for index in range(n):
		if (n - index - 1) % 2 == 0:
			allPosibilities.append(s[index:] + s[:index][::-1])
		else:
			allPosibilities.append(s[index:] + s[:index])
	answer = min(allPosibilities)
	print(answer)
	print(allPosibilities.index(answer) + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	l = min([s[i:] + s[:i][::-1] + '{:04d}'.format(i) if n - i & 1 else s[i:] + s[:i] + '{:04d}'.format(i) for i in range(n)])
	print(l[:-4], int(l[-4:]) + 1, sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	che = s.copy()
	k = 1
	for i in range(2, n + 1):
		tem = s.copy()
		ll = n - i + 1
		if ll % 2 == 0:
			tem = tem[i - 1:] + tem[:i - 1]
		else:
			tem = tem[i - 1:] + tem[:i - 1][::-1]
		if tem < che:
			che = tem
			k = i
	print(''.join(che))
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	k = -1
	candidate = [[s, 1]]
	for i in range(1, n):
		if s[i] <= s[0]:
			k = i + 1
			candidate.append([s[i:], k])
			candidate[-1][0].extend(s[:i] if (n - k + 1) % 2 == 0 else reversed(s[:i]))
	candidate.sort(key=lambda x: x[0])
	print(''.join(candidate[0][0]))
	print(candidate[0][1])


t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	a = []
	for i in range(n):
		if (n - i) % 2 != 0:
			a.append(x[i:] + x[:i][::-1])
		else:
			a.append(x[i:] + x[:i])
	m = min(a)
	print(m)
	print(a.index(m) + 1)


for i in range(int(input())):
	n = int(input())
	string = input()
	string2 = ''
	temp = string
	output = 1
	for k in range(1, n + 1):
		if (n - k + 1) % 2 == 0:
			string2 = string[k - 1] + string[k:] + string[:k - 1]
		else:
			string2 = string[k - 1] + string[k:] + string[:k - 1][::-1]
		if string2 < temp:
			temp = string2
			output = k
	print(temp)
	print(output)


for _ in range(int(input())):
	k = int(input())
	word = input()
	l = []
	for x in range(k + 1):
		if (k - x) % 2 == 0:
			l.append([word[x:] + word[:x], x + 1])
		else:
			l.append([word[x:] + word[:x][::-1], x + 1])
	l.sort()
	print(l[0][0])
	print(l[0][1])


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())

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

def lsi():
	return list(msi())
for _ in range(ii()):
	n = ii()
	s = si()
	d = s
	ans1 = 1
	c = min(s)
	b = []
	for i in range(len(s)):
		if s[i] == c:
			b.append(i)
	if s.count(c) == n:
		print(''.join(s))
		print('1')
		continue
	for k in b:
		ans = k
		x = n - ans - 1
		s1 = ''
		s1 += s[ans:]
		if x % 2 == 0:
			s2 = s[:ans]
			s2 = list(s2)
			s2.reverse()
			s1 += ''.join(s2)
		else:
			s1 += s[:ans]
		if s1 < d:
			d = s1
			ans1 = k + 1
	print(d)
	print(ans1)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	e = n % 2
	s = input().rstrip()
	k = 1
	smallest = s
	for i in range(1, n):
		if (e + i) % 2 == 0:
			if s[i:n] + s[:i] < smallest:
				smallest = s[i:n] + s[:i]
				k = i + 1
		elif s[i:n] + s[i - 1::-1] < smallest:
			smallest = s[i:n] + s[i - 1::-1]
			k = i + 1
	print(smallest)
	print(k)


T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	ans = s
	ans1 = 1
	for k in range(1, n):
		if (n - k + 1) % 2 == 0:
			s1 = s[k:] + s[:k][::-1]
		else:
			s1 = s[k:] + s[:k]
		if s1 < ans:
			ans = s1
			ans1 = k + 1
	print(ans)
	print(ans1)


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		n = int(input())
		s = input()
		possibles = []
		for i in range(n - 1):
			left = s[:i]
			right = s[i:]
			if (n - len(left)) % 2 == 0:
				possibles.append([right + left, i + 1])
			else:
				possibles.append([right + left[::-1], i + 1])
		possibles.append([s[::-1], n])
		possibles.sort()
		print(possibles[0][0])
		print(possibles[0][1])
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


t = int(input())
for z in range(t):
	n = int(input())
	s = input()
	if len(set(s[:])) == 1:
		print(s)
		print(1)
	else:
		key = sorted(s)[0]
		tempAns = s[:]
		ans = 0
		for i in range(n):
			if s[i] == key:
				temp = s[:]
				if (n - i) % 2 == 1:
					temp = temp[i:] + temp[:i][::-1]
				else:
					temp = temp[i:] + temp[:i]
				if temp < tempAns:
					tempAns = temp[:]
					ans = i
		ans += 1
		print(tempAns)
		print(ans)


t = int(input())
st = ''
for _ in range(t):
	n = int(input())
	s = input()
	l = [s + '0000']
	for i in range(1, n):
		if n - i & 1:
			st = s[i:] + s[:i][::-1] + '{:04d}'.format(i)
		else:
			st = s[i:] + s[:i] + '{:04d}'.format(i)
		l.append(st)
	l.sort()
	print(l[0][:-4])
	print(int(l[0][-4:]) + 1)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = sorted(s)
	l = []
	for i in range(len(s)):
		if s[i] == b[0]:
			l.append(i)
	q = []
	for i in range(len(l)):
		if l[i] == n - 1:
			q.append([s[::-1], n])
		elif l[i] == 0:
			q.append([s, 1])
		else:
			ans = ''
			ans += s[l[i]:]
			x = s[0:l[i]]
			if (n - l[i] - 1) % 2 == 0:
				x = x[::-1]
			ans += x
			q.append([ans, l[i] + 1])
	q.sort()
	print(q[0][0])
	print(q[0][1])


from sys import stdin, stdout
for _ in range(int(input())):
	n = int(stdin.readline().strip())
	s = stdin.readline().strip()
	k_min = 1
	s_min = s[:]
	for k in range(2, n + 1):
		s_ = s[k - 1:n]
		if (n - k + 1) % 2 == 1:
			s_ += s[:k - 1][::-1]
		else:
			s_ += s[:k - 1]
		if s_min > s_:
			k_min = k
			s_min = s_
	stdout.write(s_min + '\n')
	print(k_min)


for _ in range(int(input())):
	n = int(input())
	s = input()
	temp = min(s)
	lst = []
	for i in range(n):
		if s[i] == temp:
			lst.append(i)
	index = 0
	ans = 'z' * 5000
	for i in lst:
		if n % 2 == 0:
			if i % 2 == 0:
				temp = s[i:] + s[:i]
			else:
				temp = s[i:] + s[:i][::-1]
		elif i % 2 != 0:
			temp = s[i:] + s[:i]
		else:
			temp = s[i:] + s[:i][::-1]
		if ans > temp:
			index = i + 1
			ans = temp
	print(ans)
	print(index)


t = int(input())
for i in range(t):
	n = int(input())
	so = str(input())
	arr = {}
	for j in range(n):
		s = ''
		s += so[j:]
		if n % 2 != j % 2:
			s += so[:j][::-1]
		else:
			s += so[:j]
		arr[j + 1] = s
	arr = sorted(arr.items(), key=lambda x: x[1])
	print(arr[0][1])
	print(arr[0][0])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	tmp = []
	for i in range(n):
		(b, c) = (s[:i], s[i:])
		if (n - i) % 2:
			b = b[::-1]
		tmp.append((c + b, i + 1))
	tmp.sort()
	(x, y) = tmp[0]
	print(x)
	print(y)


def strmod(s, n, k):
	pref = s[k - 1:]
	suff = s[:k - 1]
	if n % 2 == k % 2:
		suff = suff[::-1]
	return pref + suff
for _ in range(int(input())):
	n = int(input())
	inpstr = input()
	res = strmod(inpstr, n, 1)
	res_k = 1
	for i in range(1, n):
		tmp = strmod(inpstr, n, i + 1)
		if tmp < res:
			res = tmp
			res_k = i + 1
	print(res)
	print(res_k)


for _ in range(int(input())):
	Map = {}
	n = int(input())
	s = list(input())
	Map[''.join(s)] = 1
	for k in range(1, n):
		st = ''.join(s[k:])
		if (n - k) % 2 == 0:
			st += ''.join(s[:k])
		else:
			rev = s[:k]
			rev.reverse()
			st += ''.join(rev)
		if st in Map:
			Map[st] = min(k + 1, Map[st])
		else:
			Map[st] = k + 1
	ans = ''.join(s)
	k = 1
	for i in Map:
		if i < ans:
			ans = i
			k = Map[i]
		elif i == ans:
			if Map[i] < k:
				k = Map[i]
	print(ans)
	print(k)


def solve():
	n = int(input())
	s = input()
	s_res = s
	res = 1
	for i in range(1, n):
		t = ''
		if (n - i) % 2 == 0:
			t = s[i:] + s[:i]
		else:
			t = s[i:] + s[:i][::-1]
		if t < s_res:
			s_res = t
			res = i + 1
	print('%s\n%d\n' % (s_res, res), end='')
test = int(input())
while test > 0:
	solve()
	test -= 1


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	diff = 1
	ans = s
	for i in range(0, n):
		if (n - i) % 2 == 0:
			x = s[i:] + s[:i]
		else:
			x = s[i:] + s[:i][::-1]
		if x < ans:
			diff = i + 1
			ans = x
	print(ans)
	print(diff)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	curmin = s
	mini = 1
	for c in range(1, n):
		if n % 2 ^ (c + 1) % 2:
			q = s[c:] + s[:c]
		else:
			q = s[c:] + s[:c][::-1]
		if q < curmin:
			curmin = q
			mini = c + 1
	print(curmin)
	print(mini)


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	s = data()
	answer = 'z' * 5001
	k = 0
	for i in range(n + 1):
		(t1, t2) = (s[i:], s[:i])
		if n % 2 == 0 and i % 2 == 1 or (n % 2 == 1 and i % 2 == 0):
			t2 = t2[::-1]
		if t1 + t2 < answer:
			k = i + 1
			answer = t1 + t2
	print(answer)
	print(k)


t = 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	(minStr, minIdx) = (s[:], 0)
	for i in range(n):
		comp = s[i:] + s[:i] if (n - i) % 2 == 0 else s[i:] + s[:i][::-1]
		if comp < minStr:
			minStr = comp
			minIdx = i
	print(minStr)
	print(minIdx + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	cnt = 1
	p = s
	for i in range(2, n + 1):
		t = s[i - 1:] + (s[:i - 1] if i % 2 != n % 2 else s[:i - 1][::-1])
		if p > t:
			p = t
			cnt = i
	print(p)
	print(cnt)


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import Counter
mod = 998244353

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		a = []
		ans = 'z' * n
		c = 0
		for i in range(n):
			st = s[i:] + (''.join(reversed(s[0:i])) if (n - i) % 2 == 1 else s[0:i])
			if st < ans:
				ans = st
				c = i
		print(ans)
		print(c + 1)
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')
main()


for _ in range(int(input())):
	n = int(input())
	s = input().rstrip()
	mi = s[:]
	l = 1
	for k in range(2, n + 1):
		z = s[k - 1:] + s[:k - 1][::-1] if n % 2 == k % 2 else s[k - 1:] + s[:k - 1]
		if mi > z:
			mi = z[:]
			l = k
	print(mi)
	print(l)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	m = s
	idx = 0
	for i in range(n):
		if (n - i) % 2 == 0:
			c = s[i:] + s[:i]
		else:
			c = s[i:] + s[:i][::-1]
		if m > c:
			idx = i
			m = c
	print(m)
	print(idx + 1)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	x = input()
	a = []
	for i in range(n):
		if (n - i) % 2:
			a.append(x[i:] + x[:i][::-1])
		else:
			a.append(x[i:] + x[:i])
	m = min(a)
	print(m)
	print(a.index(m) + 1)


def solv():
	x = int(input())
	s = input()
	res = s
	ans = 1
	for n in range(1, x + 1):
		a = s[:n - 1]
		b = s[n - 1:]
		p = 0
		if x % 2 == n % 2:
			a = a[::-1]
			p = 1
		if n == 0:
			b = b[::-1]
		elif n == x and p == 0:
			a = a[::-1]
		ct = n
		cur = b + a
		if cur < res:
			res = cur
			ans = n
	print(res)
	print(ans)
for _ in range(int(input())):
	solv()


test = int(input())
for i in range(test):
	strLen = int(input())
	s = input()
	best = s
	k = 0
	temp = ''
	for i in range(1, strLen + 1):
		p = s[i:strLen]
		ss = ''
		if (i + strLen) % 2:
			ss = s[0:i][::-1]
		else:
			ss = s[0:i]
		temp = p + ss
		if temp < best:
			best = temp
			k = i
	print(best)
	print(k + 1)


def sp(s, k):
	n = len(s)
	if (n - k + 1) % 2 == 0:
		b = s[k - 1:n] + s[0:k - 1]
	else:
		b = s[k - 1:n] + s[k - 2::-1]
	return b
for t in range(int(input())):
	l = int(input())
	s = input()
	ans = 1
	an = s
	for i in range(2, l + 1):
		y = sp(s, i)
		if y < an:
			an = y
			ans = i
	print(an, ans, sep='\n')


def findall(s, mn):
	pos = []
	for i in range(len(s)):
		if s[i] == mn:
			pos.append(i)
	return pos

def build(pos):
	global s
	if (len(s) - pos) % 2 == 1:
		return s[pos:] + s[:pos][::-1]
	else:
		return s[pos:] + s[:pos]
for i in range(int(input())):
	a = int(input())
	s = input()
	mn = min([i for i in s])
	pos = findall(s, mn)
	if len(pos) == 1:
		print(build(pos[0]))
		print(pos[0] + 1)
	else:
		temp = build(pos[0])
		ans = pos[0]
		for i in pos:
			bld = build(i)
			if bld < temp:
				temp = bld
				ans = i
		print(temp)
		print(ans + 1)


def maximizescore(x, y):
	return min(sum(x), y)

def modifystring(x):
	y = min(x)
	z = '{'
	l = 1
	for i in range(len(x)):
		if x[i] == y:
			if (len(x) - i) % 2 == 0:
				if z > x[i:] + x[:i]:
					z = x[i:] + x[:i]
					l = i + 1
			elif z > x[i:] + x[:i][::-1]:
				z = x[i:] + x[:i][::-1]
				l = i + 1
	return (z, l)
cases = int(input())
for _ in range(cases):
	l = int(input())
	x = input()
	print(*modifystring(x), sep='\n')


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = s
	fans = 1
	for i in range(1, n):
		if i % 2 != n % 2:
			d = s[i - 1:] + s[:i - 1]
		else:
			d = s[i - 1:] + s[:i - 1][::-1]
		if d < ans:
			ans = d
			fans = i
	if s[::-1] < ans:
		ans = s[::-1]
		fans = n
	print(ans)
	print(fans)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	m = min(s)
	l = []
	c = []
	for i in range(1, n):
		y = s[:i - 1]
		if i % 2 == n % 2:
			y = y[::-1]
		x = ''.join(s[i - 1:] + y)
		if x[0] == m and x not in l:
			l.append(x)
			c.append(i)
	l.append(''.join(s[::-1]))
	c.append(n)
	if l == []:
		print(''.join(s))
		print(1)
		continue
	j = min(l)
	print(j)
	print(c[l.index(j)])


import sys
t = int(input())
for x in range(t):
	n = int(input())
	s = input()
	ind = 0
	mini = min(s)
	d = []
	for i in range(n):
		if s[i] == mini:
			d.append(i)
	maxi = s
	n1 = len(d)
	for i in range(n1):
		s1 = ''
		cnt = 0
		s1 += s[d[i]:]
		if (n - d[i]) % 2 == 0:
			s1 += s[:d[i]]
		elif d[i] - 1 >= 0:
			s1 += s[d[i] - 1::-1]
		if maxi > s1:
			maxi = s1
			ind = d[i]
	print(''.join(maxi))
	print(ind + 1)


from collections import defaultdict
tests = int(input())

def apply_k(s, k):
	if k == 1:
		return s
	if (len(s) - k + 1) % 2 == 0:
		return s[k - 1:] + s[:k - 1]
	else:
		return s[k - 1:] + ''.join(reversed(s[:k - 1]))
for _ in range(tests):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		print(n)
		continue
	min_char = min(s)
	poss = defaultdict(list)
	for (idx, char) in enumerate(s):
		poss[char].append(idx)
	if len(poss) == 1:
		print(s)
		print(1)
		continue
	min_s = s
	min_k = 1
	possible_k = poss[min_char]
	for k in possible_k:
		k += 1
		tmp_s = apply_k(s, k)
		if tmp_s < min_s:
			min_k = k
			min_s = tmp_s
	print(min_s)
	print(min_k)


def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		s = input()
		c = s
		k = 1
		for i in range(n):
			temp = []
			temp.append(s[i:])
			if (n - i) % 2 == 0:
				temp.append(s[0:i])
			else:
				for j in range(i - 1, -1, -1):
					temp.append(s[j])
			hs = ''.join(temp)
			if hs < c:
				c = hs
				k = i + 1
		print(c)
		print(k)
main()


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		k_min = 0
		s_min = s
		for k in range(1, n):
			ss = s[k:n] + (s[:k] if (n - k) % 2 == 0 else s[k - n - 1::-1])
			if ss < s_min:
				k_min = k
				s_min = ss
		print(s_min)
		print(k_min + 1)
main()


q = int(input())
for rwer in range(q):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		print(1)
	else:
		for k in range(1, n + 1):
			if k == 1:
				bestk = 1
				bescik = s
			else:
				if (k - n) % 2 == 0:
					dod = s[:k - 1][::-1]
				else:
					dod = s[:k - 1]
				slowo = s[k - 1:n] + dod
				if slowo < bescik:
					bescik = slowo
					bestk = k
		print(bescik)
		print(bestk)


from functools import reduce

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		n = Read.int()
		a = Read.string()
		res = []
		res.append([a, 1])
		k = 2
		while k <= n:
			s = a
			if k % 2 == 1 and n % 2 == 0 or (k % 2 == 0 and n % 2 == 1):
				s = s[k - 1:k] + s[k:] + s[0:k - 1]
			else:
				s = s[k - 1:k] + s[k:] + s[0:k - 1][::-1]
			res.append([s, k])
			k += 1
		resf = res[0]
		for i in res:
			if i[0] < resf[0]:
				resf = i
		print(resf[0] + '\n' + str(resf[1]))
main()


def modified(arr, n, k):
	prfix = arr[k - 1:]
	suffix = arr[:k - 1]
	if n % 2 == k % 2:
		suffix = suffix[::-1]
	return prfix + suffix
for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	best_s = modified(arr, n, 1)
	best_k = 1
	for k in range(2, n + 1):
		temp = modified(arr, n, k)
		if temp < best_s:
			best_s = temp
			best_k = k
	print(''.join(best_s))
	print(best_k)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ans = s
	val = 1
	for k in range(1, n + 1):
		if k == n:
			tmp = s[::-1]
		else:
			ss = s[:k - 1]
			if n % 2 != k % 2:
				tmp = s[k - 1:] + ss
			else:
				tmp = s[k - 1:] + ss[::-1]
		if ans > tmp:
			ans = tmp
			val = k
	print(ans)
	print(val)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().rstrip()
	words = []
	for i in range(n):
		if (n - i) % 2 == 0:
			words.append((s[i:] + s[:i], i + 1))
		else:
			words.append((s[i:] + s[:i][::-1], i + 1))
	words.sort()
	print(words[0][0])
	print(words[0][1])


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
for __ in range(int(input())):
	n = int(input())
	s = input()
	a = []
	for i in range(n):
		if (n - i) % 2 == 0:
			a.append([s[i:] + s[:i], i])
		else:
			a.append([s[i:] + s[:i][::-1], i])
	a.sort()
	print(a[0][0])
	print(a[0][1] + 1)


import sys, os, io
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = s[:]
	k = 1
	for i in range(1, n):
		ns = s[i:]
		if (n - i) % 2:
			ns += s[:i][::-1]
		else:
			ns += s[:i]
		if ns < ans:
			ans = ns[:]
			k = i + 1
	print(ans)
	print(k)


t = int(input())
for r in range(t):
	n = int(input())
	y = input()
	a = []
	for i in range(n):
		if (n - i) % 2 == 1:
			a.append(y[i:] + y[:i][::-1])
		else:
			a.append(y[i:] + y[:i])
	ans = 0
	for i in range(n - 1):
		if a[ans] > a[i + 1]:
			ans = i + 1
	print(a[ans])
	print(ans + 1)


t = int(input())

def Modify(sting, k):
	array = list(sting)
	if k % 2 == 0 and len(sting) % 2 == 0 or k % 2 == len(sting) % 2 == 1:
		array2 = reversed(array[0:k - 1])
		array = array[k - 1:]
		array.extend(array2)
	else:
		array = array[k - 1:] + array[0:k - 1]
	return ''.join(array)
for x in range(t):
	n = int(input())
	word = input()
	leastValue = word
	leastIndex = 1
	if len(word) == 1:
		print(word)
		print(1)
	else:
		for i in range(2, len(word) + 1):
			editedWord = Modify(word, i)
			if leastValue > editedWord:
				leastValue = editedWord
				leastIndex = i
		print(leastValue)
		print(leastIndex)


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input().strip()
		ret = s
		ret_idx = 0
		for k in range(1, n):
			if (n - k) % 2 == 0:
				tmp = s[k:] + s[:k]
			else:
				tmp = s[k:] + ''.join(reversed(s[:k]))
			if ret > tmp:
				ret = tmp
				ret_idx = k
		print(ret)
		print(ret_idx + 1)
main()


def modified(s, n, k):
	result_prefix = s[k - 1:]
	result_suffix = s[:k - 1]
	if n % 2 == k % 2:
		result_suffix = result_suffix[::-1]
	return result_prefix + result_suffix
for _ in range(int(input())):
	n = int(input())
	s = input()
	best_s = modified(s, n, 1)
	best_k = 1
	for i in range(2, n + 1):
		temp = modified(s, n, i)
		if temp < best_s:
			best_s = temp
			best_k = i
	print(best_s)
	print(best_k)


t = int(input())
for i in range(t):
	len = int(input())
	s = input()
	sl = sorted(s)[0]
	ns = 'z' * (len + 1)
	min_x = len
	for x in range(len):
		if s[x] == sl:
			if (len - x - 1) % 2 == 1:
				ns_ = s[x:] + s[:x]
			else:
				ns_ = s[x:] + ''.join(list(reversed(s[:x])))
			if ns_ < ns:
				ns = ns_
				min_x = x
	print(ns)
	print(min_x + 1)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = sorted(a)
	indices = [i for (i, x) in enumerate(a) if x == b[0]]
	ans = a
	set1 = {}
	for j in indices:
		if (n - j) % 2 == 0:
			s1 = a[j:n] + a[0:j]
		else:
			s1 = a[j:n] + a[0:j][::-1]
		if set1.get(s1, 0) == 0:
			set1[s1] = j + 1
		ans = min(ans, s1)
	print(ans)
	print(set1[ans])
	n = None
	a = None
	b = None
	indices = None
	ans = None


def get_mod(s, k):
	n = len(s)
	if k == 1:
		return s
	if k == n:
		return list(reversed(s))
	pfx = s[k - 1:]
	if (n - k) % 2:
		return pfx + s[:k - 1]
	return pfx + list(reversed(s[:k - 1]))
for _ in range(int(input())):
	n = int(input())
	s = list(input())
	if len(set(s)) == 1:
		print(''.join(s))
		print(1)
		continue
	(k, s) = min([(i + 1, get_mod(s, i + 1)) for i in range(n)], key=lambda x: (x[1], x[0]))
	print(''.join(s))
	print(k)


def strrev(string):
	s = ''
	for c in string:
		s = c + s
	return s

def modifyfull(string, k, N):
	prefix = string[k - 1:]
	suffix = string[:k - 1]
	if (N - k) % 2 == 0:
		suffix = strrev(suffix)
	return prefix + suffix

def getchar(string, k, N, rep):
	if k + rep <= N:
		return string[k + rep - 1]
	else:
		return string[rep]
T = int(input())
for test in range(T):
	N = int(input())
	stringref = input()
	minchr = min(stringref)
	indices = [n + 1 for (n, chr) in enumerate(stringref) if chr == minchr]
	candidates = [modifyfull(stringref, index, N) for index in indices]
	target = 'z' * N
	index = 1
	for (n, string) in enumerate(candidates):
		if string < target:
			target = string
			index = indices[n]
	print(target, index, sep='\n')


from sys import stdin, stdout
import heapq
import math
import operator

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(input())
		string = input()
		result = [(string, 1)]
		for i in range(1, n):
			res = ''
			st = string
			prefix = st[i:n]
			suffix = st[0:i]
			if n % 2 == (i + 1) % 2:
				suffix = suffix[::-1]
				res = prefix + suffix
			else:
				res = prefix + suffix
			result.append((res, i + 1))
		result.sort()
		print(result[0][0])
		print(result[0][1])
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	b = []
	ind = 0
	ma = ''
	for i in range(n):
		if (n - i) % 2 == 1:
			b.append(s[i:] + s[:i][::-1])
		else:
			b.append(s[i:] + s[:i])
		if i == 0:
			ind = 0
			ma = b[0]
		elif b[i] < ma:
			ma = b[i]
			ind = i
	print(ma)
	print(ind + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	string = input()
	ans = 0
	result = string
	for i in range(0, n):
		choti = string[0:i]
		if n % 2 == (i + 1) % 2:
			choti = choti[::-1]
		new = string[i:] + choti
		if new < result:
			result = new
			ans = i
	print(result)
	print(ans + 1)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	s = input()
	temp = []
	for k in range(1, n + 1):
		if (n - k + 1) % 2 == 0:
			s1 = s[k - 1:] + s[:k - 1]
		else:
			x = s[:k - 1]
			y = x[::-1]
			s1 = s[k - 1:] + y
		temp.append(s1)
	m = sorted(temp)
	pos = temp.index(m[0])
	print(m[0])
	print(pos + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	r = list(s)
	a = min(r)
	mink = 1
	wow = s
	for i in range(n):
		if r[i] == a:
			temp = s[i:] + (s[:i] if (n - i) % 2 == 0 else s[:i][::-1])
			if temp < wow:
				wow = temp
				mink = i + 1
	print(wow)
	print(mink)


from sys import stdin
MAX = 1005

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

def solve(s):
	ans = []
	sz = len(s)
	for k in range(0, sz):
		if (sz - k) % 2:
			ans.append((s[k:] + s[:k][-1::-1], k + 1))
		else:
			ans.append((s[k:] + s[:k], k + 1))
	ans.sort()
	(s, k) = ans[0]
	print(s)
	print(k)

def main():
	tc = int(line())
	for _ in range(tc):
		n = int(line())
		s = line()
		solve(s)
main()


from bisect import bisect_left, bisect_right, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque

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

def mdata():
	return map(int, data().split())
for i in range(int(data())):
	n = int(data())
	s = input()
	s1 = s[0]
	s2 = s[0]
	m = s
	ind = 0
	for i in range(1, n):
		if (n - i) % 2 == 0:
			t = s[i:n] + s1
			if t < m:
				m = t
				ind = i
		else:
			t = s[i:n] + s2
			if t < m:
				m = t
				ind = i
		s1 += s[i]
		s2 = s[i] + s2
	print(m)
	print(ind + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ch = s[0]
	for i in range(1, n):
		if ch > s[i]:
			ch = s[i]
	ks = []
	for i in range(n):
		if s[i] == ch:
			ks.append(i + 1)
	low = -1
	for k in ks:
		rev = False
		if (n - k + 1) % 2 == 1:
			rev = True
		temp = s[k - 1:n]
		str1 = s[0:k - 1]
		if rev:
			str1 = str1[::-1]
		temp = temp + str1
		if low == -1 or ans > temp:
			low = k
			ans = temp
	print(ans)
	print(low)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = str(input())
		res = [(1, s)]
		for k in range(2, n + 1):
			temp = s[k - 1:n]
			if (n - k + 1) % 2 == 1:
				temp += s[:k - 1][::-1]
			else:
				temp += s[:k - 1]
			res.append((k, temp))
		r = sorted(res, key=lambda x: (x[1], x[0]))
		print(r[0][1])
		print(r[0][0])
main()


def f(L, K):
	L = list(L)
	a = L[:K - 1]
	ans = L[K - 1:]
	if K % 2 == len(L) % 2:
		a = a[::-1]
	ans += a
	return ''.join(ans)
for _ in range(int(input())):
	N = int(input())
	L = input()
	ans = 'z' * 6000
	ak = -1
	for k in range(1, 1 + N):
		x = f(L, k)
		if x < ans:
			ans = x
			ak = k
	print(ans)
	print(ak)


for _ in range(int(input())):
	n = int(input())
	s = input()
	(ans, pos) = (s, 1)
	for k in range(2, n + 1):
		t = n - k + 1
		t2 = s[:k - 1]
		if t % 2 != 0:
			t2 = t2[::-1]
		temp = s[-t:] + t2
		if temp < ans:
			ans = temp
			pos = k
	print(ans)
	print(pos)


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

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

def iinput():
	return int(input())

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	n = iinput()
	s = input()
	d = defaultdict(list)
	for k in range(n):
		temp = s[k:]
		if (n - k + 1) % 2 == 0:
			temp += s[:k][::-1]
		else:
			temp += s[:k]
		d[temp].append(k)
	print(min(d))
	print(min(d[min(d)]) + 1)


for i in range(int(input())):
	n = int(input())
	s = input()
	if n == 1:
		print(s)
		print(n)
		continue
	s1 = ''
	index = 0
	l = []
	for j in range(1, n + 1):
		s2 = ''
		s1 = s[j - 1:]
		s2 += s[0:j - 1]
		if len(s2) % 2 == 1 and n % 2 == 1 or (n % 2 == 0 and len(s2) % 2 == 0):
			s1 += s2
		else:
			s1 += s2[::-1]
		l.append(s1)
	l1 = l.copy()
	l.sort()
	print(l[0])
	print(l1.index(l[0]) + 1)


def reversed(strr, k):
	for i in range(len(strr) - k + 1):
		revd = strr[i:i + k][::-1]
		strr = strr[:i] + revd + strr[i + k:]
	return strr
hm = int(input())
for u in range(hm):
	n = int(input())
	s = input()
	r = ''
	x = s
	c = 1
	for i in range(n):
		r = r + s[i:n]
		h = s[0:i]
		if (n - i) % 2 == 1:
			h = h[::-1]
		r = r + h
		if r < x:
			x = r
			c = 1 + i
		r = ''
	print(x)
	print(c)


def rotate(l, n):
	if (len(l) - n) % 2 == 1:
		l_ = l[n - 1:] + l[:n - 1]
	else:
		l_ = l[n - 1:] + ''.join(reversed(l[:n - 1]))
	return l_
t = int(input())
for t_ in range(t):
	n = int(input())
	s = input()
	(ans, now) = (s, 1)
	for i in range(1, len(s) + 1):
		s_ = rotate(s, i)
		if s_ < ans:
			ans = s_
			now = i
	print(ans)
	print(now)


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	s = input()
	ss = s
	ans = 1
	ansstr = s
	for i in range(n):
		temp = s[0:i]
		temp1 = s[i:]
		x = temp1 + temp
		if (n - (i + 1)) % 2 == 0:
			temp = temp[::-1]
		temp1 = temp1 + temp
		if temp1 < ansstr:
			ans = i + 1
			ansstr = temp1
	print(ansstr, ans, sep='\n')


from sys import stdin, stdout
ke = int(stdin.readline())
s = [0] * ke
for gh in range(ke):
	a = int(input())
	b = '{' + input()
	z = min(b)
	ok = [0] * b.count(z)
	j = 0
	for i in range(1, a + 1):
		if b[i] == z:
			o = b[i:]
			if a - i & 1 == 0:
				o += b[1:i][::-1]
			else:
				o += b[1:i]
			ok[j] = [o, i]
			j += 1
	l = min(ok)
	s[gh] = ''.join(l[0]) + '\n' + str(l[1])
stdout.write('\n'.join(s))


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 1
	ansString = s
	for i in range(n - 1):
		temp = s[i:] + (s[:i] if (n - i) % 2 == 0 else s[:i][::-1])
		if temp < ansString:
			ans = i + 1
			ansString = temp
	temp = s[::-1]
	if temp < ansString:
		ans = n
		ansString = temp
	print(ansString[:n])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	x = min(list(s))
	t = s
	m = 1
	for i in range(n):
		if s[i] == x:
			if i != n - 1:
				y = s[i:]
				if len(y) % 2 == 0:
					y += s[:i]
				else:
					y += s[:i][::-1]
			else:
				y = s[::-1]
			if t > y:
				t = y
				m = i + 1
			elif t == y:
				m = min(m, i + 1)
	print(t)
	print(m)


def reverseString(s, begin, end):
	return s[0:begin] + s[begin:end][::-1] + s[end:]
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	m = s
	index = 0
	for i in range(n):
		if (n - i) % 2 == 0:
			c = s[i:] + s[:i]
		else:
			c = s[i:] + s[:i][::-1]
		if m > c:
			m = c
			index = i
	print(m)
	print(index + 1)


import sys

def input():
	return sys.stdin.readline().rstrip()
for T in range(int(input())):
	n = int(input())
	s = input()
	ans = s
	k = 1
	for i in range(n):
		s2 = s[i:]
		if n % 2 == i % 2:
			s2 += s[:i]
		else:
			s2 += s[:i][::-1]
		if s2 < ans:
			ans = s2
			k = i + 1
	print(ans)
	print(k)


import sys
import math
import bisect

def query(s, m):
	n = len(s)
	if (n - m + 1) % 2 == 0:
		return s[m - 1:n] + s[0:m - 1]
	else:
		return s[m - 1:n] + s[0:m - 1][::-1]

def solve(s):
	n = len(s)
	min_val = s
	sol = 1
	for i in range(2, n + 1):
		val = query(s, i)
		if min_val > val:
			min_val = val
			sol = i
	return (min_val, sol)

def main():
	for _ in range(int(input())):
		n = int(input())
		s = input()
		ans = solve(s)
		print(ans[0])
		print(ans[1])
main()


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		A = list(input())
		if len(set(A)) == 1:
			print(''.join(A), 1, sep='\n')
			continue
		min_character = min(A)
		possible_modifications = []
		possible_k = []
		for k in range(1, n + 1):
			if A[k - 1] == min_character:
				current_A = A[:]
				tmp = current_A[:k - 1]
				if (n - k) % 2 == 0:
					tmp = tmp[::-1]
				current_A = current_A[k - 1:] + tmp
				possible_modifications.append(current_A)
				possible_k.append(k)
		min_modification = min(possible_modifications)
		print(''.join(min_modification), possible_k[possible_modifications.index(min_modification)], sep='\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	string = input()
	ind = 1
	ans = string
	if string[-1::-1] < string:
		ans = min(string, string[-1::-1])
		ind = n
	if n % 2 == 0:
		for i in range(1, n - 1):
			if i % 2 == 0:
				if string[i:] + string[0:i] < ans or (string[i:] + string[0:i] == ans and i + 1 < ind):
					ans = string[i:] + string[0:i]
					ind = i + 1
			elif string[i:] + string[i - 1::-1] < ans or (string[i:] + string[i - 1::-1] == ans and i + 1 < ind):
				ans = string[i:] + string[i - 1::-1]
				ind = i + 1
	else:
		for i in range(1, n - 1):
			if i % 2 == 1:
				if string[i:] + string[0:i] < ans or (string[i:] + string[0:i] == ans and i + 1 < ind):
					ans = string[i:] + string[0:i]
					ind = i + 1
			elif string[i:] + string[i - 1::-1] < ans or (string[i:] + string[i - 1::-1] == ans and i + 1 < ind):
				ans = string[i:] + string[i - 1::-1]
				ind = i + 1
	print(ans)
	print(ind)


for _ in range(int(input())):
	n = int(input())
	original_str = input()
	min_str = original_str
	min_k = 0
	for i in range(1, n + 1):
		if n & 1:
			if i % 2 == 0:
				cur = original_str[i:] + original_str[0:i][::-1]
			else:
				cur = original_str[i:] + original_str[0:i]
		elif i % 2 == 0:
			cur = original_str[i:] + original_str[0:i]
		else:
			cur = original_str[i:] + original_str[0:i][::-1]
		if cur < min_str:
			min_str = cur
			min_k = i
	print(min_str + '\n' + str(min_k + 1))


for _ in range(int(input())):
	n = int(input())
	min_string = 'z' * n
	s = input()
	for k in range(1, n + 1):
		if (n - k) % 2 == 0:
			candidate = s[k - 1:n] + s[:k - 1][::-1]
		else:
			candidate = s[k - 1:n] + s[:k - 1]
		if candidate < min_string:
			min_string = candidate
			accepted_k = k
	print(min_string)
	print(accepted_k)


def stringModification(n, string):
	lexSmallest = string
	ks = 1
	for k in range(1, n + 1):
		if (n - k) % 2 == 0:
			stri = string[k - 1:] + string[k - 2::-1]
		else:
			stri = string[k - 1:] + string[:k - 1]
		if stri < lexSmallest:
			lexSmallest = stri
			ks = k
	return (ks, lexSmallest)
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(a, ans) = stringModification(n, s)
	print(ans)
	print(a)


for _ in range(int(input())):
	input()
	s = input()
	n = len(s)
	ans = s
	final = 1
	for k in range(n):
		if n % 2:
			if k % 2:
				temp = s[k:] + s[0:k]
			else:
				temp = s[k:] + s[0:k][::-1]
		elif k % 2 == 0:
			temp = s[k:] + s[0:k]
		else:
			temp = s[k:] + s[0:k][::-1]
		if temp < ans:
			ans = temp
			final = k + 1
	print(ans)
	print(final)


def reverse(s):
	return s[::-1]
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	p = sorted(s)[0]
	arr = []
	for i in range(len(s)):
		if s[i] == p:
			arr.append(i)
	lis = []
	for i in arr:
		if (n - i) % 2 == 0:
			lis.append((s[i:] + s[0:i], i + 1))
		else:
			lis.append((s[i:] + reverse(s[0:i]), i + 1))
	lis.sort(key=lambda x: x[0])
	print(lis[0][0])
	print(lis[0][1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = []
	for i in range(1, n + 1):
		if i == n:
			temp = s[-1::-1]
		elif (n - i + 1) % 2 == 0:
			temp = s[i - 1:] + s[:i - 1]
		else:
			temp = s[i - 1:] + s[:i - 1][::-1]
		ans.append([temp, i])
	m = ans[0][0]
	el = 1
	for i in range(1, len(ans)):
		if ans[i][0] < m:
			(m, el) = ans[i]
	print('{}\n{}'.format(m, el))


for _ in range(int(input())):
	n = int(input())
	s = input()
	b = [s[i:] + s[:i][::-1] if (n - i - 1) % 2 == 0 else s[i:] + s[:i] for i in range(n)]
	print(min(b))
	print(b.index(min(b)) + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	m = min(s)
	smallest = []
	for i in range(n):
		if s[i] == m:
			smallest.append(i + 1)
	d = {}
	for i in smallest:
		if i % 2 == 0 and n % 2 == 0 or (i % 2 != 0 and n % 2 != 0):
			t = s[:i - 1]
			t = t[::-1]
			temp = s[i - 1:] + t
			if temp not in d:
				d[temp] = i
		else:
			temp = s[i - 1:] + s[:i - 1]
			if temp not in d:
				d[temp] = i
	ans = min(sorted(d))
	print(ans)
	print(d[ans])


t = int(input())
while t:
	n = int(input())
	s = input()
	d = {}
	mini = 200
	for i in range(n):
		if d.get(ord(s[i]), -1) == -1:
			d[ord(s[i])] = []
		d[ord(s[i])].append(i)
		if ord(s[i]) < mini:
			mini = ord(s[i])
	l_s = {}
	d[mini].sort()
	ld = []
	ch = 0
	for i in range(len(d[mini])):
		s1 = ''
		cnt = 0
		s1 += s[d[mini][i]:]
		cnt = n - d[mini][i]
		if cnt % 2 == 0:
			s1 += s[:d[mini][i]]
		elif d[mini][i] - 1 >= 0:
			s1 += s[d[mini][i] - 1::-1]
		if l_s.get(s1, -1) == -1:
			l_s[s1] = d[mini][i]
			ld.append(s1)
	ld.sort()
	print(ld[0])
	print(l_s[ld[0]] + 1)
	t -= 1


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 500010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

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

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = s
	k = 1
	for i in range(2, n + 1):
		x = s[:i - 1]
		if (n - (i - 1)) % 2:
			t = s[i - 1:] + x[::-1]
		else:
			t = s[i - 1:] + x
		if t < ans:
			ans = t
			k = i
	print(ans)
	print(k)


from operator import itemgetter
from collections import *
for i in range(int(input())):
	(n, s) = (int(input()), input())
	(arr, d) = ([[s, 1]], deque(s))
	for j in range(1, n):
		arr.append([s[j:] + s[:j][::-1], j + 1] if (n - j) % 2 else [s[j:] + s[:j], j + 1])
	arr.sort(key=itemgetter(0, 1))
	print(arr[0][0])
	print(arr[0][1])


t = int(input())
while t:
	n = int(input())
	s = input()
	ls = []
	for i in range(1, n + 1):
		if (n - i - 1) % 2 == 0:
			temp = s[i - 1:] + s[0:i - 1]
		else:
			temp = s[i - 1:] + s[0:i - 1][::-1]
		ls.append([temp, i])
	ls.sort()
	print(ls[0][0])
	print(ls[0][1])
	t -= 1


from math import *
zzz = int(input())
for zz in range(zzz):
	n = int(input())
	s = input()
	mik = -1
	ms = ''
	for k in range(1, n + 1):
		ts = ''
		if k % 2 == 1 and n % 2 == 0 or (k % 2 == 0 and n % 2 == 1):
			ts = s[k - 1:] + s[:k - 1]
		else:
			tk = s[:k - 1]
			ts = s[k - 1:] + tk[::-1]
		if ts < ms or mik == -1:
			mik = k
			ms = ts
	print(ms)
	print(mik)


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	ss = s + s
	ans = [['', 0] for i in range(n)]
	for i in range(1, n + 1):
		if i % 2 == len(s) % 2:
			ans[i - 1][0] = s[i - 1:] + s[:i - 1][::-1]
		else:
			ans[i - 1][0] = s[i - 1:] + s[:i - 1]
		ans[i - 1][1] = i
	ans.sort(key=lambda x: (x[0], x[1]))
	print(ans[0][0])
	print(ans[0][1])


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	mk = 1
	ms = ''
	ms += s
	for k in range(2, n + 1):
		new = s[0:k - 1]
		if (n - k + 1) % 2 == 1:
			new = new[::-1]
		if ms > s[k - 1:n] + new:
			mk = k
			ms = s[k - 1:n] + new
	print(ms)
	print(mk)


import sys
from collections import defaultdict

def solve(N, S):
	best = [(S[k:] + S[:k][::-1], k + 1) if (N - k) % 2 == 1 else (S[k:] + S[:k], k + 1) for k in range(0, N)]
	if False:
		check = []
		for k in range(1, N + 1):
			s = list(S)
			for i in range(0, N - k + 1):
				s[i:i + k] = s[i:i + k][::-1]
			check.append((''.join(s), k))
		best.sort()
		check.sort()
		assert sorted(best) == sorted(check)
	best = min(best)
	return best[0] + '\n' + str(best[1])
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(N,) = list(map(int, input().split()))
	S = input().rstrip()
	ans = solve(N, S)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ok = min(s)
	hehe = ''
	(dapan, vitri) = (s, 1)
	for i in range(1, n + 1):
		if s[i - 1] == ok:
			if (n - i + 1) % 2 == 0:
				hehe = s[i - 1:] + s[:i - 1]
			else:
				hehe = s[i - 1:] + s[:i - 1][::-1]
			if hehe < dapan:
				dapan = hehe
				vitri = i
	print(dapan)
	print(vitri)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = [[s, 1]]
	for k in range(1, n):
		(a, b) = (s[:k], s[k:])
		if (n + k) % 2 == 1:
			l.append([b + a[::-1], k + 1])
		else:
			l.append([b + a, k + 1])
	l.sort()
	print(l[0][0])
	print(l[0][1])


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')
from math import ceil
for _ in range(int(input())):
	n = int(input())
	s = input()
	di = {s: 1}
	ans = [s]
	pre = ['']
	prerev = ['']
	for i in s:
		pre += [pre[-1] + i]
		prerev += [i + prerev[-1]]
	post = ['']
	for i in range(n - 1, -1, -1):
		post += [s[i] + post[-1]]
	ans = s
	for i in range(2, n):
		if i % 2 == n % 2:
			next = post[-(i - 1) - 1] + prerev[i - 1]
		else:
			next = post[-(i - 1) - 1] + pre[i - 1]
		ans = ans if ans < next else next
		if next not in di:
			di[next] = i
	srev = s[::-1]
	if srev not in di:
		di[srev] = n
	ans = srev if ans > srev else ans
	print(ans)
	print(di[ans])


t = int(input())
while t:
	n = int(input())
	s = input()
	m = s
	mk = 1
	for k in range(2, n + 1):
		tmp = s[k - n - 1:] + (s[k - 2::-1] if (n - k + 1) % 2 == 1 else s[:k - 1])
		if tmp < m:
			m = tmp
			mk = k
	print(m)
	print(mk)
	t -= 1


e = int(input())
p = []
f = []
for ee in range(e):
	n = int(input())
	s = str(input())
	sr = s
	words = []
	er = []
	er.append(s)
	words.append(s)
	for k in range(2, n + 1):
		j = ''
		j = s[k - 1:]
		if (len(s) - k + 1) % 2 == 0:
			j = j + s[:k - 1]
		else:
			g = s[:k - 1]
			g = g[::-1]
			j = j + g
		words.append(j)
		er.append(j)
	words.sort()
	for i in range(len(er)):
		if words[0] == er[i]:
			f.append(i + 1)
			break
	p.append(words[0])
for i in range(len(p)):
	print(p[i])
	print(f[i])


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		n = nu()
		s = input()
		mn = 1
		val = s
		for i in range(2, n + 1):
			x = s[0:i - 1]
			y = s[i - 1:]
			op = n - i + 1
			if op % 2 == 0:
				up = y + x
			else:
				up = y + x[::-1]
			if up < val:
				val = up
				mn = i
		print(val)
		print(mn)
solve()


for _ in ' ' * int(input()):
	a = int(input())
	b = ['{'] + input().replace('', ' ').split()
	z = min(b)
	ok = [0] * b.count(z)
	j = 0
	for i in range(1, a + 1):
		if b[i] == z:
			o = b[i:]
			if a - i & 1 == 0:
				o += b[1:i][::-1]
			else:
				o += b[1:i]
			ok[j] = [o, i]
			j += 1
	l = min(ok)
	print(''.join(l[0]))
	print(l[1])


t = int(input())

def mk(k_list, k, n):
	k_left = k_list[:k - 1]
	k_right = k_list[k - 1:]
	if k % 2 == n % 2:
		k_left.reverse()
	return k_right + k_left
for t0 in range(t):
	n0 = int(input())
	s = input()
	S = [ord(g) for g in s]
	smin = min(S)
	ind = []
	counter = 0
	for h in S:
		if h == smin:
			ind.append(counter)
		counter += 1
	res1 = mk(S, ind[0] + 1, n0)
	kres = ind[0] + 1
	for k0 in ind[1:]:
		res2 = mk(S, k0 + 1, n0)
		if res2 < res1:
			res1 = list(res2)
			kres = k0 + 1
	res = [chr(x) for x in res1]
	print(''.join(res))
	print(kres)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	stringList = []
	stringList.append({'k': 1, 's': s})
	i = 1
	while i < n:
		decisionVal = n - i
		firstPart = s[i:]
		lastPart = s[0:i]
		if decisionVal % 2 == 1:
			lastPart = lastPart[::-1]
		stringList.append({'k': i + 1, 's': firstPart + lastPart})
		i += 1
	smallest = stringList[0]
	i = 1
	while i < n:
		if stringList[i]['s'] < smallest['s']:
			smallest = stringList[i]
		i += 1
	print(smallest['s'])
	print(smallest['k'])
	t -= 1


for _ in range(int(input())):
	s = [input() for i in 'aa'][1]
	idx = [i for i in range(len(s)) if s[i] == min(s)]
	ss = [s[i:] + s[:i][::-1] if (len(s) + i) % 2 != 0 else s[i:] + s[:i] for i in idx]
	print(min(ss), idx[ss.index(min(ss))] + 1, sep='\n')


for _ in range(int(input())):
	n = int(input())
	l = input()
	t = None
	m = min(l)
	k = 1
	ans = []
	for i in range(n):
		if n - i & 1:
			ans.append(l[i:] + l[0:i][::-1])
		else:
			ans.append(l[i:] + l[0:i])
	m = min(ans)
	print(m)
	print(ans.index(m) + 1)


def main():
	from sys import stdin, stdout
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		inp = stdin.readline().strip()
		temp = list(inp)
		temp.sort()
		alpha = temp[0]
		indices = []
		for i in range(n):
			if inp[i] == alpha:
				indices.append(i)
		ans = []
		for i in indices:
			temp = ''
			if n & 1:
				if i + 1 & 1:
					temp = inp[i - n - 1::-1]
				else:
					temp = inp[:i]
			elif i + 1 & 1:
				temp = inp[:i]
			else:
				temp = inp[i - n - 1::-1]
			ans.append([inp[i:] + temp, i + 1])
		ans.sort()
		stdout.write(ans[0][0] + '\n' + str(ans[0][1]) + '\n')
main()


def pomen(s, n, x):
	nach = s[x - 1:]
	end = s[:x - 1]
	if n % 2 == x % 2:
		end = end[::-1]
	return nach + end
t = int(input())
for i in range(t):
	n = int(input())
	x = input()
	k = 0
	string = x
	for j in range(2, n + 1):
		string1 = pomen(x, n, j)
		if string1 < string:
			string = string1
			k = j - 1
	print(string)
	print(k + 1)


t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	ans = ''
	k_ans = 1
	for j in range(n):
		if ans == '':
			ans = s[j:] + s[0:j][::-1]
		else:
			x = ''
			if n % 2 != (j + 1) % 2:
				x = s[j:] + s[0:j]
			else:
				x = s[j:] + s[0:j][::-1]
			if x < ans:
				ans = x
				k_ans = j + 1
	print(ans)
	print(k_ans)


def swap(s, k):
	if (len(s) + k) % 2 == 0:
		s = s[k - 1:] + s[0:k - 1][::-1]
	else:
		s = s[k - 1:] + s[0:k - 1]
	return s
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = [(s, 1)]
	for i in range(2, n + 1):
		ans.append((swap(s, i), i))
	ans = min(ans)
	print(ans[0])
	print(ans[1])


t = int(input())
for k1 in range(t):
	n = int(input())
	s = input()
	mins = 'z' * (n + 1)
	min_val = 0
	for i in range(1, n + 1):
		if (n - i) % 2 == 0:
			t = s[i - 1:] + s[:i - 1][::-1]
		else:
			t = s[i - 1:] + s[:i - 1]
		if mins > t:
			min_val = i
			mins = t
	print(mins)
	print(min_val)


import sys
from collections import Counter

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	S = input()
	ans = [(S, 1)]
	for k in range(2, N + 1):
		(s, t) = (S[:k - 1], S[k - 1:])
		if k % 2 ^ N % 2:
			s = t + s
		else:
			s = t + s[::-1]
		ans.append((s, k))
	ans.sort()
	print(ans[0][0])
	print(ans[0][1])


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	mx = s
	ind = 0
	for i in range(1, n):
		suff = ''
		if i > 0:
			suff = s[:i]
		if (n % 2 == 0 and i % 2 == 1 or (n % 2 == 1 and i % 2 == 0)) and i > 0:
			suff = suff[::-1]
		if s[i:] + suff < mx or (i == 0 and s[i:] + suff == mx):
			mx = s[i:] + suff
			ind = i
	print(mx)
	print(ind + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	k = 1
	res = s
	for j in range(1, n + 1):
		mov = n - j + 1
		t = s[:j - 1]
		final = s[j - 1:]
		if mov % 2 == 0:
			final += t
		else:
			final = final + t[::-1]
		if res > final:
			k = j
			res = final
	print(res)
	print(k)


def reversesub(s, begin, end):
	s1 = s[0:begin]
	s2 = s[begin:end][::-1]
	s3 = s[end:]
	str = s1 + s2 + s3
	if begin < end:
		return str
	else:
		return str

def Problem(str, n):
	out = []
	for k in range(0, n):
		t = str[0:k]
		if (n - k) % 2 == 1:
			t = t[::-1]
		out.append(str[k:] + t)
	n = len(out)
	mini = 0
	min = out[0]
	for j in range(0, n):
		if out[j] < min:
			mini = j
			min = out[j]
	print(min)
	print(mini + 1)
t = int(input())
while t > 0:
	n = int(input())
	str = input()
	Problem(str, n)
	t -= 1


a = int(input())
for i in range(a):
	s = int(input())
	s = input()
	ans = []
	for i in range(len(s)):
		if i == 0:
			ans.append([s, 1])
		elif 1 == 1:
			q = ''
			t = s[0:i]
			if i % 2 == 1:
				if len(s) % 2 == 0:
					q = s[i:] + t[::-1]
				else:
					q = s[i:] + t
			elif len(s) % 2 == 1:
				q = s[i:] + t[::-1]
			else:
				q = s[i:] + t
			ans.append([q, i + 1])
	ans.sort()
	print(ans[0][0])
	print(ans[0][1])


n = int(input())
for j in range(n):
	m = int(input())
	s = input()
	minS = s
	now1 = s[0]
	now2 = s[1:]
	minK = 1
	for k in range(1, m):
		now = now2
		if (m - k) % 2 == 0:
			now += now1
		else:
			now += now1[::-1]
		if now < minS:
			minS = now
			minK = k + 1
		now1 += s[k]
		now2 = now2[1:]
	print(minS)
	print(minK)


def revrse(s):
	return s[::-1]

def parity(n, k):
	return True if n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1) else False
for test in range(int(input())):
	n = int(input())
	s = input()
	(ans, ansk) = (s, 1)
	for k in range(2, n + 1):
		c = s[k - 1:]
		if parity(n, k):
			c += revrse(s[:k - 1])
		else:
			c += s[:k - 1]
		if c < ans:
			(ans, ansk) = (c, k)
	print(ans, '\n', ansk, sep='')


q = int(input())
for i in range(q):
	n = int(input())
	s = input()
	mn = min(list(s))
	ans = s
	k = 0
	for i in range(n):
		if s[i] == mn:
			new = s[:i][::-1] if (n - i - 1) % 2 == 0 else s[:i]
			if ans > s[i:] + new:
				ans = s[i:] + new
				k = i
	print(ans)
	print(k + 1)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	ansS = ''
	ansInd = -1
	if n % 2 == 0:
		do = 0
	else:
		do = 1
	for j in range(1, n + 1):
		if j % 2 == do:
			suffix = s[:j - 1][::-1]
		else:
			suffix = s[:j - 1]
		tempS = s[j - 1:] + suffix
		if j == 1:
			ansS = tempS
			ansInd = 1
		elif ansS > tempS:
			ansS = tempS
			ansInd = j
	print(ansS)
	print(ansInd)


t = int(input())
for _ in range(t):
	n = int(input())
	S = list((ord(s) - 97 for s in input()))
	C = S
	ans = 1
	for i in range(2, n + 1):
		N = [0] * n
		for j in range(i - 1, n):
			N[j - (i - 1)] = S[j]
		for j in range(i - 1):
			if (n - i + 1) % 2 == 0:
				N[n - i + 1 + j] = S[j]
			else:
				N[n - 1 - j] = S[j]
		Chk = False
		for j in range(n):
			if C[j] == N[j]:
				continue
			elif C[j] > N[j]:
				Chk = True
				break
			else:
				break
		if Chk:
			ans = i
			C = N
	Ans = ''
	for c in C:
		Ans += chr(97 + c)
	print(Ans)
	print(ans)


def f():
	n = int(input())
	s = input()
	rk = 0
	rs = s
	for k in range(1, n):
		if (n - k) % 2:
			cur = s[k:] + s[:k][::-1]
		else:
			cur = s[k:] + s[:k]
		if cur < rs:
			rs = cur
			rk = k
	print(rs)
	print(rk + 1)
t = int(input())
for i in range(t):
	f()


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	k = []
	arr = []
	for i in range(0, n):
		s1 = s[i:n + 1]
		s2 = s[0:i]
		if n % 2 != 0 and i % 2 == 0:
			s2 = s2[::-1]
		elif n % 2 == 0 and i % 2 != 0:
			s2 = s2[::-1]
		k.append(s1 + s2)
	for i in range(0, len(k)):
		arr.append(k[i])
	arr.sort()
	ans = -1
	for i in range(0, len(k)):
		if k[i] == arr[0]:
			ans = i + 1
			break
	print(arr[0])
	print(ans)
	t = t - 1


t = input()
for _ in range(int(t)):
	n = int(input())
	s = input()
	mn = min(s)
	ind = []
	for i in range(n):
		if s[i] == mn:
			ind.append(i)
	ans = 'z' * (n + 1)
	k = -1
	parity_len = n % 2
	for i in ind:
		parity_curr = i % 2
		front = s[i:i + n]
		rest = s[0:i]
		if parity_len != parity_curr:
			rest = rest[::-1]
		front = front + rest
		if front < ans:
			ans = front
			k = i
	print(ans)
	print(k + 1)


from sys import stdin
T = int(input())
for _ in range(T):
	n = int(input())
	s = input()
	small = ord(s[0])
	for letter in s:
		if ord(letter) < small:
			small = ord(letter)
	small_ind = []
	for i in range(n):
		if ord(s[i]) == small:
			small_ind.append(i)
	compare = []
	for ind in small_ind:
		diff = n - ind - 1
		diff = 1 - 2 * ((diff + 1) % 2)
		compare.append((s[ind:] + s[0:ind][::diff], ind))
	compare.sort()
	print(compare[0][0])
	print(compare[0][1] + 1)


for _ in range(int(input())):
	n = int(input())
	a = input()
	x = a
	s = sorted(a)[0]
	p = 1
	if n == 1:
		print(a, '\n', n, sep='')
	else:
		for i in range(1, n):
			if a[i - 1] == s:
				c = a[i - 1:] + (a[:i - 1][::-1] if not (n - i) % 2 else a[:i - 1])
				if c < x:
					x = c
					p = i
		if a[::-1] < x:
			x = a[::-1]
			p = n
		print(x, '\n', p, sep='')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input().rstrip()
	if n == 1:
		print(s)
		print(n)
		continue
	lst = [s]
	for i in range(1, n):
		if (i + n) % 2 == 0:
			lst.append(s[i:] + s[:i])
		else:
			lst.append(s[i:] + s[i - 1::-1])
	idx = lst.index(min(lst))
	print(lst[idx])
	print(idx + 1)


n = int(input())
l = []
for _ in range(n):
	m = input()
	x = [i for i in input()]
	l.append(x)

def compare_c(min_ind, line_ind) -> tuple:
	x = []
	for i in min_ind:
		a = ''.join(l[line_ind][i:])
		if (len(l[line_ind]) - i) % 2 == 0:
			a = a + ''.join(l[line_ind][:i])
		else:
			q = l[line_ind][:i]
			q.reverse()
			a = a + ''.join(q)
		x.append((a, i))
	q = min(x)
	return q
for i in range(len(l)):
	min_c = min(l[i])
	min_ind = []
	for j in range(len(l[i])):
		if l[i][j] == min_c:
			min_ind.append(j)
	x = compare_c(min_ind, i)
	print(x[0])
	print(x[1] + 1)


import sys
input = sys.stdin.readline
tc = int(input())

def newallswap(x, k):
	n = len(x)
	if k == 1:
		return x
	if k == len(x):
		return x[::-1]
	b = n % 2
	a = x[k - 2::-1] if k % 2 == b else x[:k - 1]
	y = x[k - 1:] + a
	return y
for _ in range(tc):
	n = int(input())
	a = input().rstrip()
	x = list(a)
	t = min(a)
	y = x
	index = []
	for k in range(2, len(x) + 1):
		if a[k - 1] == t:
			index.append(k)
	m = 1
	for k in index:
		new = newallswap(x, k)
		if y > new:
			y = new
			m = k
	print(''.join(y))
	print(m)


def solve():
	n = int(input().strip())
	s = input().strip()

	def f(k):
		if (n - k + 1) % 2 == 0:
			return s[k - 1:] + s[:k - 1]
		return s[k - 1:] + s[:k - 1][::-1]
	(res, k) = min(((f(i), i) for i in range(1, n + 1)))
	print(res)
	print(k)

def main():
	for _ in range(int(input().strip())):
		solve()
main()


tests = int(input())
for i in range(tests):
	length = int(input())
	string = input()
	mink = 1
	minstring = string
	for k in range(1, length + 1):
		if (length - k) % 2 == 0:
			if string[k - 1:] + string[:k - 1][::-1] < minstring:
				minstring = string[k - 1:] + string[:k - 1][::-1]
				mink = k
		elif string[k - 1:] + string[:k - 1] < minstring:
			minstring = string[k - 1:] + string[:k - 1]
			mink = k
	print(minstring)
	print(mink)


def ii():
	return int(input())

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

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		n = ii()
		s = input()
		r = []
		x = []
		y = []
		pt = []
		for i in range(n):
			r.append(s[i])
		rx = list(set(r))
		rx.sort()
		for i in range(n):
			p = []
			q = []
			xs = ''
			ys = ''
			vr = ''
			if s[i] == rx[0]:
				xs = s[i:]
				ys = s[:i]
				if (n - i) % 2 == 1:
					ys = ys[::-1]
				vr = xs + ys
				q.append(vr)
				q.append(i + 1)
			if len(q) != 0:
				y.append(q)
			if vr != '':
				x.append(vr)
		res = min((sub for sub in x if isinstance(sub, str)))
		for i in range(len(y)):
			if y[i][0] == res:
				pt.append(y[i][1])
		pt.sort()
		print(res)
		print(pt[0])
main()


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	(mi, m1) = (s, 1)
	for i in range(2, n + 1):
		s1 = ''
		if (n - i) % 2 == 0:
			s1 = s[i - 1:] + s[:i - 1][::-1]
		else:
			s1 = s[i - 1:] + s[:i - 1]
		if s1 < mi:
			(mi, m1) = (s1, i)
	print(mi)
	print(m1)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		s = rs()
		z = list(s)
		mn = min(z)
		mins = 'z' * 5000
		k = 1
		for i in range(n):
			if s[i] == mn:
				ns = ''
				ps = ''
				ns += s[i:]
				ps = s[:i]
				yo = i
				if i != 0 and (n - i) % 2 == 1:
					ps = ps[::-1]
				ns += ps
				if ns < mins:
					mins = ns
					k = i + 1
		print(mins)
		print(k)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	l = []
	l.append(s)
	for j in range(1, n):
		l.append(s[j:] + s[:j])
	if n % 2 == 1:
		for j in range(2, n, 2):
			t = l[j]
			u = t[:n - j]
			v = t[n - j:]
			w = v[::-1]
			l[j] = u + w
	if n % 2 == 0:
		for j in range(3, n, 2):
			t = l[j]
			u = t[:n - j]
			v = t[n - j:]
			w = v[::-1]
			l[j] = u + w
	l.append(s[::-1])
	print(min(l))
	print(l.index(min(l)) + 1)


from sys import stdin, stdout

def gen(s, k):
	flag = len(s) + k & 1
	return s[k - 1:] + (s[:k - 1][::-1] if not flag else s[:k - 1])
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline().rstrip()
	(bestK, bestS) = (float('inf'), chr(ord('z') + 1))
	for k in range(1, n + 1):
		newS = gen(s, k)
		if newS < bestS:
			(bestK, bestS) = (k, newS)
	stdout.write('%s\n%d\n' % (bestS, bestK))


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = dict()
	a[s] = 1
	for j in range(1, n + 1):
		if j == 1:
			continue
		u = n - j + 1
		z = s[0:j - 1]
		if u % 2 == 1:
			z = z[::-1]
		s1 = s[j - 1:] + z
		if s1 in a:
			continue
		a[s1] = j
	l = list(a.keys())
	l.sort()
	print(l[0])
	print(a[l[0]])


import sys
input = sys.stdin.readline

def rank_compare(x):
	if x + k < LEN:
		return (RANK[x] << 17) + RANK[x + k]
	elif x < LEN:
		return RANK[x] << 17
	return -1
t = int(input())
for tests in range(t):
	n = int(input())
	S = tuple(input().strip())
	MIN = min(S)
	STLIST = []
	for k in range(n):
		if S[k] != MIN:
			continue
		if (n - k) % 2 == 0:
			STLIST.append((S[k:] + S[:k], k + 1))
		else:
			STLIST.append((S[k:] + S[:k][::-1], k + 1))
	STLIST.sort()
	sys.stdout.write(''.join(STLIST[0][0]) + '\n')
	sys.stdout.write(str(STLIST[0][1]) + '\n')


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	temp = a.copy()
	test = a.copy()
	i = 1
	ans = 1
	while i < n:
		if ord(a[i]) <= ord(a[0]):
			if (n - i) % 2 != 0:
				j = 0
				for k in range(i, n):
					temp[j] = a[k]
					j += 1
				for k in range(i - 1, -1, -1):
					temp[j] = a[k]
					j += 1
				for (j, k) in zip(test, temp):
					if ord(j) < ord(k):
						break
					elif ord(k) < ord(j):
						test = temp.copy()
						ans = i + 1
						break
			else:
				j = 0
				for k in range(i, n):
					temp[j] = a[k]
					j += 1
				for k in range(i):
					temp[j] = a[k]
					j += 1
				for (j, k) in zip(test, temp):
					if ord(j) < ord(k):
						break
					elif ord(k) < ord(j):
						test = temp.copy()
						ans = i + 1
						break
		i += 1
	print(''.join(test))
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(input())
	q = []
	m = s
	ans = 1
	for i in range(n):
		if i % 2 == n % 2:
			r = s[i:] + s[0:i]
		else:
			r = s[i:] + s[0:i][::-1]
		if r < m:
			m = r
			ans = i + 1
	print(''.join(m))
	print(ans)


t = 0
t = int(input())
for q in range(t):
	n = int(input())
	str = ''
	str = input()
	ans_str = ''
	ans_ind = 0
	for i in range(n):
		if (n - i + 1) % 2 == 0:
			new_str = str[i:n] + str[0:i][::-1]
		else:
			new_str = str[i:n] + str[0:i]
		if i == 0:
			ans_str = new_str
			ans_ind = 0
		elif new_str < ans_str:
			ans_str = new_str
			ans_ind = i
	print(ans_str)
	print(ans_ind + 1)


def get_pos(in_str, len_0, sym):
	pos = []
	for i in range(len_0):
		if sym == in_str[i]:
			pos.append(i + 1)
	return pos

def rev_str(in_str, len_0, k):
	temp = list(in_str)
	(i, t) = (0, len_0 - k + 1)
	k_even = k % 2
	l_even = len_0 % 2
	if k == 1:
		return temp
	elif k == len_0:
		return list(reversed(temp))
	else:
		if k_even ^ l_even == 0:
			temp = temp[k - 1:] + list(reversed(temp[:k - 1]))
		else:
			temp = temp[k - 1:] + temp[:k - 1]
		return temp
t_count = int(input().strip())
while t_count != 0:
	len_0 = int(input().strip())
	in_str = input().strip()
	pos = get_pos(in_str, len_0, min(in_str))
	results = []
	for i in pos:
		results.append((rev_str(in_str, len_0, i), i))
	results.sort()
	print(''.join(results[0][0]))
	print(results[0][1])
	t_count -= 1


t = int(input())

def replace_k(s, k):
	coef = len(s) - k + 1
	if k == len(s):
		return s[::-1]
	return s[k - 1:] + (s[:k - 1] if coef % 2 == 0 else s[:k - 1][::-1])

def solve(s):
	(min_s, res) = (s, 1)
	for k in range(1, len(s) + 1):
		replaced = replace_k(s, k)
		if min_s > replaced:
			min_s = replaced
			res = k
	return (res, min_s)
for i in range(t):
	_ = input()
	s = input()
	(res, min_s) = solve(s)
	print(min_s)
	print(res)


for _ in range(int(input())):
	n = int(input())
	l = input()
	ans = 1
	m = l
	for i in range(n):
		if i % 2 == n % 2:
			new = l[i:] + l[0:i]
		else:
			new = l[i:] + l[0:i][::-1]
		if new < m:
			m = new
			ans = i + 1
	print(m)
	print(ans)


test = int(input())
while test != 0:
	n = int(input())
	s = input()
	diff = 1
	ansS = s
	for i in range(0, n):
		if (n - i) % 2 == 0:
			x = s[i:] + s[:i]
		else:
			x = s[i:] + s[:i][::-1]
		if x < ansS:
			diff = i + 1
			ansS = x
		elif x == ansS:
			if i + 1 < diff:
				diff = i + 1
	print(ansS)
	print(diff)
	test -= 1


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
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')

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

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

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')
import bisect

def main():
	for _ in range(N()):
		n = N()
		s = input()
		tag = s
		res = 1
		for i in range(1, n):
			ns = s[i:] + (s[:i] if (n - i) % 2 == 0 else s[:i][::-1])
			if ns < tag:
				tag = ns
				res = i + 1
		print(tag)
		print(res)
main()


t = int(input())
for you in range(t):
	n = int(input())
	s = input()
	pref = [0 for i in range(n)]
	suffer = [0 for i in range(n)]
	real = [0 for i in range(n)]
	sumi = ''
	suf = ''
	reo = ''
	for i in range(n):
		sumi = s[n - i - 1] + sumi
		pref[n - 1 - i] = sumi
		suf = s[i] + suf
		reo = reo + s[i]
		real[i] = reo
		suffer[i] = suf
	lfi = []
	curr = 1
	for i in range(n - 1, -1, -1):
		if i == n - 1 and i != 0:
			lfi.append((pref[n - 1] + suffer[n - 2], i))
			curr = 0
		else:
			if i == 0:
				lfi.append((s, i))
				continue
			if curr:
				lfi.append((pref[i] + suffer[i - 1], i))
				curr = 0
			else:
				curr = 1
				lfi.append((pref[i] + real[i - 1], i))
	lfi.sort()
	print(lfi[0][0])
	print(lfi[0][1] + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	copy = s
	for i in range(1, n):
		if (n - i + 1) % 2 == 1:
			p = s[i:] + s[:i]
			if p < copy:
				copy = p
				ans = i
		else:
			p = s[i:] + s[:i][::-1]
			if p < copy:
				copy = p
				ans = i
	print(copy)
	print(ans + 1)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input()
	poss = []
	for i in range(n):
		if n - i & 1 and i != 0:
			poss.append([a[i:] + a[i - 1::-1], i])
		else:
			poss.append([a[i:] + a[:i], i])
	(ans, k) = min(poss)
	print(ans)
	print(k + 1)


t = int(input())
for mo in range(1, t + 1):
	l = []
	n = int(input())
	s = input()
	for i in range(1, n + 1):
		if (n - i + 1) % 2 and i >= 2:
			l.append((s[i - 1:] + s[i - 2::-1], i))
		elif (n - i + 1) % 2:
			l.append((s, i))
		else:
			l.append((s[i - 1:] + s[:i - 1], i))
	print(min(l)[0])
	print(min(l)[1])


for _ in range(int(input())):
	n = int(input())
	s = input()
	temp = s
	ans = 1
	for p in range(n):
		if n % 2 == 0:
			if p % 2 == 0:
				if s[p:] + s[:p] < temp:
					temp = s[p:] + s[:p]
					ans = p + 1
			else:
				aux = s[p:] + s[0:p][::-1]
				if aux < temp:
					temp = aux
					ans = p + 1
		elif p % 2 == 0:
			aux = s[p:] + s[0:p][::-1]
			if aux < temp:
				temp = aux
				ans = p + 1
		elif s[p:] + s[:p] < temp:
			temp = s[p:] + s[:p]
			ans = p + 1
	print(temp)
	print(ans)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(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
	return prime
MAXN = int(1000000.0 + 5)
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')

def find_parent(parent, i, cnt):
	cnt += 1
	if parent[i - 1] == i:
		return cnt
	if parent[i - 1] != i:
		find_parent(parent, parent[i - 1], cnt)
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = n
	var = s
	for i in range(1, n + 1):
		if n % 2 == (i - 1) % 2:
			str = s[i - 1:] + s[:i - 1]
		else:
			str = s[i - 1:] + s[:i - 1][::-1]
		if str < var:
			var = str
			ans = i
		elif str == var:
			if i < ans:
				ans = i
	print(var)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	r = sorted(s)
	l = []
	for i in range(len(s)):
		if s[i] == r[0]:
			l.append(i)
	q = []
	for i in range(len(l)):
		if l[i] == 0:
			q.append([s, 1])
		elif l[i] == n - 1:
			q.append([s[::-1], n])
		else:
			temp = []
			ans = ''
			ans += s[l[i]:]
			e = s[0:l[i]]
			if (l[i] + 1) % 2 and (n - l[i] - 1) % 2 == 0 or ((l[i] + 1) % 2 == 0 and (n - l[i] - 1) % 2 == 0):
				e = e[::-1]
			ans += e
			q.append([ans, l[i] + 1])
	q.sort()
	print(q[0][0])
	print(q[0][1])


def modify(s, k):
	prefix = s[k:n]
	suffix = s[0:k]
	if len(s) % 2 != k % 2:
		suffix = suffix[::-1]
	return prefix + suffix
t = int(input())
for t_itr in range(0, t):
	n = int(input())
	s = input()
	minchar = -1
	minin = float('inf')
	arr = []
	for i in range(0, n):
		if ord(s[i]) < minin:
			minin = ord(s[i])
			minchar = i
	arr.append(minchar)
	for i in range(0, n):
		if s[i] == s[minchar]:
			if i not in arr:
				arr.append(i)
	modified = modify(s, arr[0])
	mins = modified
	mink = arr[0]
	if len(arr) > 1:
		for i in range(1, len(arr)):
			modified = modify(s, arr[i])
			if modified < mins:
				mins = modified
				mink = arr[i]
	print(mins)
	print(mink + 1)


t = int(input())
R = lambda : map(int, input().split())
for i in range(t):
	n = int(input())
	s = input()
	ans = []
	for i in range(1, n + 1):
		if i == n:
			temp = s[::-1]
			ans.append((temp, i))
			continue
		if (n - i - 1) % 2 == 0:
			temp = s[i - 1:] + s[:i - 1]
		else:
			temp = s[i - 1:] + s[:i - 1][::-1]
		ans.append((temp, i))
	z = min(ans)
	print(z[0])
	print(z[1])


import sys
import math
t = int(input())
while t:
	n = int(input())
	s = input()
	d = {}
	ind = 0
	mini = 200
	for i in range(n):
		if d.get(ord(s[i]), -1) == -1:
			d[ord(s[i])] = []
		d[ord(s[i])].append(i)
		if ord(s[i]) < mini:
			mini = ord(s[i])
	l_s = {}
	maxi = s
	d[mini].sort()
	ld = []
	for i in range(len(d[mini])):
		s1 = ''
		cnt = 0
		s1 += s[d[mini][i]:]
		if (n - d[mini][i]) % 2 == 0:
			s1 += s[:d[mini][i]]
		elif d[mini][i] - 1 >= 0:
			s1 += s[d[mini][i] - 1::-1]
		if maxi > s1:
			maxi = s1
			ind = d[mini][i]
	print(maxi)
	print(ind + 1)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	mn = 'z'
	for i in s:
		if mn > i:
			mn = i
	d = []
	for i in range(n):
		if s[i] == mn:
			if (i + 1) % 2 == 0 and len(s) % 2 == 0 or ((i + 1) % 2 != 0 and len(s) % 2 != 0):
				d.append((s[i:] + s[:i][::-1], i + 1))
			else:
				d.append((s[i:] + s[:i], i + 1))
	ans = list(min(d))
	print(ans[0])
	print(ans[1])


def sim(s, t):
	if len(s) == t:
		return s[::-1]
	if (len(s) - t) % 2 == 0:
		return s[t:] + s[:t]
	else:
		return s[t:] + s[:t][::-1]

def f(s):
	n = len(s)
	t = min([(sim(s, i), i) for i in range(0, n + 1, 1)], key=lambda x: x[0])
	return (t[0], t[1] + 1)
for i in range(int(input())):
	n = int(input())
	s = input()
	print(*f(s), sep='\n')


def get_ns(s, n, k):
	if (n + k) % 2 != 0:
		return s[k - 1:] + s[:k - 1]
	return s[k - 1:] + s[k - 2::-1]

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		m = s
		mk = 1
		for k in range(2, n + 1):
			ns = get_ns(s, n, k)
			if m > ns:
				m = ns
				mk = k
		print(m)
		print(mk)
main()


t = int(input())
for T in range(t):
	n = int(input())
	s = input()
	cand = s
	k = 1
	for i in range(n):
		if (i + n) % 2 == 0:
			new = s[i:] + s[:i]
		else:
			new = s[i:] + s[:i][::-1]
		if new < cand:
			cand = new
			k = i + 1
	print(cand)
	print(k)


def reverse(s):
	return s[::-1]
for t in range(int(input())):
	n = int(input())
	s = input()
	alls = []
	for k in range(1, n + 1):
		news = s[k - 1:] + (s[:k - 1] if (n - k + 1) % 2 == 0 else reverse(s[:k - 1]))
		alls.append((news, k))
	(s, k) = min(alls)
	print(s)
	print(k)


INF = 10 ** 10

def main():
	n = get_int()
	st = input()
	mini = st
	ans = 1
	for k in range(1, n + 1):
		a = st[:k - 1]
		if (n - k + 1) % 2 != 0:
			a = a[::-1]
		s = st[k - 1:] + a
		if s < mini:
			ans = k
			mini = s
	print(''.join(mini))
	print(ans)
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
if sys.version_info[0] < 3:
	input = raw_input
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]


def solve(inp):
	sorted_inp = ''.join(sorted(inp))
	if inp == sorted_inp:
		return (inp, 1)
	smallest_letter = sorted_inp[0]
	smallest_indices = [i for (i, v) in enumerate(inp) if v == smallest_letter]
	best_result = inp
	best_k = 1
	for k in smallest_indices:
		num_substrings = len(inp) - k
		cur_choice = inp[k:] + inp[:k] if num_substrings % 2 == 0 else inp[k:] + ''.join(reversed(inp[:k]))
		if cur_choice < best_result:
			best_result = cur_choice
			best_k = k + 1
	return (best_result, best_k)
t = int(input())
for i in range(t):
	l = int(input())
	inp = input()
	(res, k) = solve(inp)
	print(res + '\n' + str(k))


for _ in range(int(input())):
	n = int(input())
	s = input()
	l = []
	for i in range(1, n + 1):
		p = []
		for j in range(i - 1, n):
			p.append(s[j])
		ks = i - 2
		q = n - i + 1
		if q % 2 == 0:
			k = 0
			while k <= ks:
				p.append(s[k])
				k += 1
		else:
			k = i - 2
			while k > -1:
				p.append(s[k])
				k -= 1
		l.append((''.join(p), i))
	l.sort()
	print(l[0][0])
	print(l[0][1])


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(input())
	curr = ''.join(s)
	ind = 1
	m = min(s)
	for i in range(len(s)):
		if s[i] == m:
			prev = curr
			if (n - i) % 2 == 1:
				curr = min(curr, ''.join(s[i:] + list(reversed(s[:i]))))
			else:
				curr = min(curr, ''.join(s[i:] + s[:i]))
			if prev != curr:
				ind = i + 1
	print(curr)
	print(ind)


def modi(s):
	pres = ['']
	poss = []
	revpos = []
	revpres = ['']
	spr = ''
	spo = ''
	rpo = ''
	rpr = ''
	for i in s:
		spr += i
		pres.append(spr)
		rpr = i + rpr
		revpres.append(rpr)
	for i in s[::-1]:
		spo += i
		rpo = i + rpo
		revpos.append(rpo)
		poss.append(spo)
	L = []
	c = 0
	ss = 'z' * 5000
	for k in range(1, len(s) + 1):
		if (len(s) - k) % 2:
			t = revpos[len(s) - k] + pres[k - 1]
		else:
			t = revpos[len(s) - k] + revpres[k - 1]
		if ss > t:
			c = k
			ss = t
	return (ss, c)
for i in ' ' * int(input()):
	input()
	(s, c) = modi(input())
	print(s)
	print(c)


def v(string, k):
	ops = len(string) - k
	if ops % 2 == 1:
		return string[k:] + string[:k][::-1]
	return string[k:] + string[:k]
t = int(input())
for _ in range(t):
	length = int(input())
	to_modify = input()
	modified_strings = [to_modify]
	k = 1
	while k <= length and v(to_modify, k) not in modified_strings:
		modified_strings.append(v(to_modify, k))
		k += 1
	print(min(modified_strings))
	print(modified_strings.index(min(modified_strings)) + 1)


n = int(input())
for t in range(0, n):
	strLen = int(input())
	string = input()
	smallest = string[0]
	for i in string:
		if i < smallest:
			smallest = i
	candidates = []
	ranges = []
	for i in range(0, strLen):
		if string[i] == smallest:
			shift = string[i:]
			other = string[0:i]
			if (strLen - i) % 2 == 1:
				shift += other[::-1]
			else:
				shift += other
			candidates.append(shift)
			ranges.append(i)
	bestCandidate = candidates[0]
	bestRange = ranges[0]
	for i in range(0, len(candidates)):
		if candidates[i] < bestCandidate:
			bestCandidate = candidates[i]
			bestRange = ranges[i]
	print(bestCandidate)
	print(bestRange + 1)


t = int(input())
for tt in range(t):
	n = int(input())
	s = input()
	mi = s
	mik = 1
	for k in range(1, n + 1):
		d = n - k + 1
		suf = s[-d:]
		pre = s[:-d]
		if d % 2 == 1:
			pre = pre[::-1]
		ss = suf + pre
		if ss < mi:
			mi = ss
			mik = k
	print(mi)
	print(mik)


import sys
input = sys.stdin.readline

def rev(s, n, k):
	i = k - 1
	cnt = n - i
	return s[i:] + (s[:i] if cnt % 2 == 0 else s[:i][::-1])
t = int(input())
for _ in range(t):
	n = int(input())
	s = input().strip()
	mn = 1
	ss = rev(s, n, 1)
	for k in range(2, n + 1):
		cur = rev(s, n, k)
		if cur < ss:
			mn = k
			ss = cur
	print(ss)
	print(mn)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	if len(set(s)) == 1:
		print(''.join(s))
		print(1)
	else:
		m = min(s)
		ans = s[:]
		ind = 1
		for (i, c) in enumerate(s):
			fs = s[i:] + s[:i][::-1 if (i + n) % 2 == 1 else 1]
			if fs < ans:
				ans = fs
				ind = i + 1
		print(''.join(ans))
		print(ind)


inp = int(input())
for i in range(inp):
	wlen = int(input())
	word = input() * 2
	my_dict = {}
	prev = word[0:wlen]
	prevrev = prev[::-1]
	k = 0
	for j in range(wlen - 1):
		if j % 2 == wlen % 2:
			word_j_wlen_j_ = word[j:wlen + j]
			if word_j_wlen_j_ < prev:
				prev = word_j_wlen_j_
				k = j
		else:
			word_j_wlen_j_ = word[j:wlen] + word[j - 1::-1]
			if word_j_wlen_j_ < prev:
				prev = word_j_wlen_j_
				k = j
	if prevrev < prev:
		k = wlen - 1
		prev = prevrev
	print(prev)
	print(k + 1)


T = int(input())
for _ in range(T):
	N = int(input())
	S = input()
	mi = chr(123)
	for k in range(1, N + 1):
		if (N ^ k) & 1:
			a = S[k - 1:] + S[:k - 1]
		else:
			a = S[k - 1:] + S[:k - 1][::-1]
		if a < mi:
			mi = a
			mik = k
	print(mi)
	print(mik)


t = int(input())
for i in range(t):
	le = int(input())
	s = list(input())
	mg = s[:]
	i1 = 1
	co = 0
	for k in range(le):
		if le % 2 != 0:
			if k % 2 == 0:
				l = s[0:k]
				r = s[k:le]
				l.reverse()
				ne = r + l
				if ne < mg:
					mg = ne
					i1 = k + 1
			else:
				l = s[0:k]
				r = s[k:le]
				ne = r + l
				if ne < mg:
					mg = ne
					i1 = k + 1
		elif k % 2 != 0:
			l = s[0:k]
			r = s[k:le]
			l.reverse()
			ne = r + l
			if ne < mg:
				mg = ne
				i1 = k + 1
		else:
			l = s[0:k]
			r = s[k:le]
			ne = r + l
			if ne < mg:
				mg = ne
				i1 = k + 1
	print(''.join(mg))
	print(i1)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	lis = []
	for i in range(n):
		if i == 0:
			lis.append((s, 1))
		else:
			if len(s[i:]) % 2 == 0:
				s1 = s[i:] + s[:i]
			else:
				s1 = s[i:] + s[:i][::-1]
			lis.append((s1, i + 1))
	x = min(lis)
	print(x[0])
	print(x[1])


import math, sys
from collections import defaultdict, Counter, deque
from functools import reduce
INF = float('inf')
MOD = int(1000000000.0) + 7

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = defaultdict(int)
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors[i] += 1
			n //= i
		i += 1
	if n > 1:
		factors[n] += 1
	return factors

def main():
	n = int(input())
	s = input()
	ans = s
	i = 0
	res = 0
	prev = ''
	suf = s
	while i < n:
		if (n - i) % 2 == 1:
			rs = suf + prev[::-1]
		else:
			rs = suf + prev
		if rs < ans:
			ans = rs
			res = i
		prev += s[i]
		i += 1
		suf = suf[1:]
	print(ans)
	print(res + 1)

class DSU:

	def __init__(self, n):
		self.p = [i for i in range(n + 1)]
		self.size = [1 for i in range(n + 1)]
		self.minmax = [[i, i] for i in range(n + 1)]
		self.n = n

	def find(self, node):
		if self.p[node] != node:
			self.p[node] = self.find(self.p[node])
		return self.p[node]

	def union(self, source, dest):
		source = self.find(source)
		dest = self.find(dest)
		if source != dest:
			if self.size[source] < self.size[dest]:
				(source, dest) = (dest, source)
			self.p[dest] = source
			self.size[source] += self.size[dest]
			mini = min(self.minmax[source][0], self.minmax[dest][0])
			maxi = max(self.minmax[source][1], self.minmax[dest][1])
			self.minmax[source] = [mini, maxi]

def input():
	return sys.stdin.readline().rstrip('\n')

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

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

def array():
	return list(map(int, input().split()))
t = 1
t = int(input())
for _ in range(t):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	ans = 122
	for i in range(n):
		ans = min(ans, ord(a[i]))
	index = []
	for i in range(n):
		if ord(a[i]) == ans:
			index = index + [i]
	l = len(index)
	i = 0
	b = a[:]
	vendam = n - index[0] + 2
	if vendam % 2 == 0:
		now = b[index[0]:] + b[:index[0]]
	else:
		c = b[:index[0]]
		now = b[index[i]:] + c[::-1]
	ansind = index[i] + 1
	for i in range(1, l):
		vendam = n - index[i] + 2
		b = a[:]
		c = a[:]
		if vendam % 2 == 0:
			now1 = b[index[i]:] + c[:index[i]]
		else:
			c = b[:index[i]]
			now1 = b[index[i]:] + c[::-1]
		if now > now1:
			now = now1
			ansind = index[i] + 1
	print(now)
	print(ansind)


for t in range(int(input())):
	n = int(input())
	s = input()
	bk = 1
	m = s
	for k in range(1, n + 1):
		u = s[0:k - 1]
		if (n - k) % 2 == 0:
			u = u[::-1]
		v = s[k - 1:] + u
		if v < m:
			bk = k
			m = v
	print(m)
	print(bk)


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

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

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

def main():
	n = aint()
	s = input()
	ans1 = s
	ans2 = 1
	for k in range(1, n):
		if (n - k) % 2 == 1:
			sd = s[k:] + s[:k][::-1]
		else:
			sd = s[k:] + s[:k]
		if sd < ans1:
			ans1 = sd
			ans2 = k + 1
	print(ans1)
	print(ans2)
t = aint()
for i in range(t):
	main()


import math
q = int(input())
for _ in range(q):
	n = int(input())
	l = list(input())
	ans = 1
	m = l
	for i in range(n):
		if i % 2 == n % 2:
			new = l[i:] + l[0:i]
		else:
			new = l[i:] + l[0:i][::-1]
		if new < m:
			m = new
			ans = i + 1
	print(''.join(m))
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	s = stdin.readline().strip()
	all_str = []
	for k in range(n):
		pol = (n - k) % 2
		if pol == 0:
			all_str.append((s[k:] + s[:k], k + 1))
		else:
			all_str.append((s[k:] + s[:k][::-1], k + 1))
	all_str = sorted(all_str, key=lambda ele: (ele[0], ele[1]))
	stdout.write(all_str[0][0] + '\n')
	stdout.write(str(all_str[0][1]) + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	currMinK = 1
	currMinS = s
	for k in range(2, n + 1):
		if (n + k) % 2 == 1:
			currS = s[k - 1:] + s[:k - 1]
		else:
			currS = s[k - 1:] + s[:k - 1][::-1]
		if currS < currMinS:
			currMinK = k
			currMinS = currS
	if s[::-1] < currMinS:
		currMinS = s[::-1]
		currMinK = n
	print(currMinS)
	print(currMinK)


numTests = int(input())
minLexIx = 0
answers = []
for i in range(numTests):
	strLen = int(input())
	word = input()
	results = []
	for ix in range(0, strLen):
		res = word[ix:strLen]
		rhs = word[0:ix]
		if ix % 2 == 0 and strLen % 2 == 1 or (ix % 2 == 1 and strLen % 2 == 0):
			rhs = rhs[::-1]
		res += rhs
		results.append(res)
	minIx = 0
	minAns = results[0]
	for (ix, ans) in enumerate(results):
		if ans < minAns:
			minAns = ans
			minIx = ix
	answers.append((minAns, minIx))
for a in answers:
	print(a[0])
	print(str(a[1] + 1))


from sys import stdin

def func():
	return
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = stdin.readline().strip()
	d = {0: s}
	for i in range(1, n):
		m = s[i:]
		if n % 2 != 0:
			if i % 2 == 0:
				rest = s[0:i][::-1]
			else:
				rest = s[0:i]
		elif i % 2 != 0:
			rest = s[0:i][::-1]
		else:
			rest = s[0:i]
		m += rest
		d[i] = m
	m_val = d[0]
	k = 1
	for i in range(1, n):
		if d[i] < m_val:
			m_val = d[i]
			k = i + 1
	print(m_val)
	print(k)


t = int(input())
for i in range(0, t):
	n = int(input())
	s = input()
	ss = s
	ans = 1
	for j in range(2, n):
		s1 = s[j - 1:]
		if n % 2 == 0 and j % 2 != 0:
			s2 = s[:j - 1]
		elif n % 2 == 0 and j % 2 == 0:
			s2 = s[:j - 1]
			s2 = s2[::-1]
		elif n % 2 != 0 and j % 2 == 0:
			s2 = s[:j - 1]
		elif n % 2 != 0 and j % 2 != 0:
			s2 = s[:j - 1]
			s2 = s2[::-1]
		s3 = s1 + s2
		if s3 < ss:
			ss = s3
			ans = j
	s3 = s[::-1]
	if s3 < ss:
		ss = s3
		ans = n
	print(ss)
	print(ans)


import sys
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(' ')]

def main():
	solns = []
	t = readInt()
	for _ in range(t):
		n = readInt()
		s = readLine().rstrip()
		substrings = []
		for i in range(len(s)):
			substring = s[i:]
			if i % 2 != n % 2:
				substring += ''.join(reversed(s[:i]))
			else:
				substring += s[:i]
			substrings.append((i + 1, substring))
		leastString = min((s for s in substrings), key=lambda x: (x[1], x[0]))
		solns.append(leastString[1])
		solns.append(leastString[0])
	print('\n'.join((str(x) for x in solns)))
	return
main()


for _ in range(int(input())):
	n = int(input())
	s = input()
	r = s
	d = 0
	for i in range(1, n):
		if (n - i) % 2 == 1:
			a = s[i:] + s[:i][::-1]
		else:
			a = s[i:] + s[:i]
		if a < r:
			r = a
			d = i
	print(r)
	print(d + 1)


def aze(a, n):
	sol = a
	ans = 1
	k = 2
	while k < n + 1:
		if (n - k + 1) % 2 == 0:
			b = a[:k - 1]
		else:
			b = a[:k - 1]
			b = b[::-1]
		if a[k - 1:] + b < sol:
			sol = a[k - 1:] + b
			ans = k
		k += 1
	return (sol, ans)
t = int(input())
for i in range(t):
	n = int(input())
	s = str(input())
	(sol, ans) = aze(s, n)
	print(sol)
	print(ans)


INF = 10 ** 10

def main():
	print = out.append
	n = get_int()
	st = input()
	mini = st
	ans = 1
	for k in range(1, n + 1):
		a = st[:k - 1]
		if (n - k + 1) % 2 != 0:
			a = a[::-1]
		s = st[k - 1:] + a
		if s < mini:
			ans = k
			mini = s
	print(''.join(mini))
	print(ans)
import sys
from collections import defaultdict, Counter, deque
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
[main() for _ in range(int(input()))]
print(*out, sep='\n')


t = int(input())
while t:
	t -= 1
	n = int(input())
	s = input()
	s = '_' + s
	v = []
	for i in range(1, n + 1):
		if (n - i + 1) % 2:
			v.append((s[i:] + s[1:i][::-1], i))
		else:
			v.append((s[i:] + s[1:i], i))
	v.sort()
	print(v[0][0])
	print(v[0][1])


no_of_test_cases = int(input())
for i in range(0, 2 * no_of_test_cases, 2):
	length = int(input())
	string = input()
	list_string = []
	fixed_list = []
	for k in range(0, length - 1):
		if (length - k) % 2 == 0:
			list_string = list_string + [string[k:] + string[:k]]
			fixed_list = fixed_list + [string[k:] + string[:k]]
		if (length - k) % 2 == 1:
			list_string = list_string + [string[k:] + string[:k][::-1]]
			fixed_list = fixed_list + [string[k:] + string[:k][::-1]]
	list_string = list_string + [string[::-1]]
	fixed_list = fixed_list + [string[::-1]]
	list_string.sort()
	req_ele = list_string[0]
	req_k = fixed_list.index(req_ele)
	print(req_ele)
	print(req_k + 1)


t = int(input())
while t > 0:
	t -= 1
	len = int(input())
	s = input()
	res = 1
	sstr = s
	for i in range(len):
		ss = s[i:]
		if len - i & 1 == 0:
			ss = ss + s[0:i]
		else:
			ss = ss + ''.join(reversed(s[0:i]))
		if sstr > ss:
			sstr = ss
			res = i + 1
	print(sstr)
	print(res)


T = int(input())
for tt in range(T):
	n = int(input())
	s = input()
	best_s = None
	best_k = None
	for k in range(1, n + 1):
		s1 = s[:k - 1]
		s2 = s[k - 1:]
		if (n - k) % 2 == 1:
			new_s = s2 + s1
		else:
			new_s = s2 + s1[::-1]
		if best_s is None or new_s < best_s:
			best_s = new_s
			best_k = k
	print(best_s)
	print(best_k)


def swap(s, n, k):
	if (n - k + 1) % 2 == 0:
		return s[k - 1:] + s[:k - 1]
	return s[k - 1:] + s[:k - 1][::-1]
for _ in range(int(input())):
	n = int(input())
	s = input()
	a = []
	c = ''
	m = s
	k = 0
	for i in 'abcdefghijklmnopqrstuvwxyz':
		if i in s:
			c = i
			break
	for i in range(n):
		if c == s[i]:
			a.append(i)
	for i in a:
		if i == 0:
			k = 1
		else:
			t = swap(s, n, i + 1)
			if m > t:
				k = i + 1
				m = t
	print(m)
	print(k)


for _ in range(int(input())):
	n = int(input())
	s = input()
	l1 = []
	l2 = []
	min_ = min(s)
	for i in range(n):
		if s[i] == min_:
			l1.append(i)
	for i in l1:
		s1 = s[i:]
		if (n - i) % 2 == 0:
			s1 += s[:i]
		else:
			s1 += s[:i][::-1]
		l2.append(s1)
	x = min(l2)
	print(x)
	print(l1[l2.index(x)] + 1)


import math
t = int(input())
for w in range(t):
	n = int(input())
	s = input()
	k = 1
	s1 = s
	for i in range(2, n + 1):
		if (n - i + 1) % 2 == 0:
			s2 = s[i - 1:] + s[:i - 1]
		else:
			s2 = s[i - 1:] + s[:i - 1][::-1]
		if s2 < s1:
			k = i
			s1 = s2
	print(s1)
	print(k)


t = int(input())
for T in range(t):
	n = int(input())
	s = input()
	k = 1
	hh = len(s)
	pp = ''
	for i in range(1, n):
		p = s[:i - 1]
		dd = s[i - 1:]
		if (n - i) % 2 == 0:
			p = p[::-1]
		ff = dd + p
		if len(pp) == 0 or pp > ff:
			k = i
			pp = ff
	ff = s[::-1]
	if len(pp) == 0 or pp > ff:
		pp = ff
		k = n
	print(pp)
	print(k)


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	n = int(input())
	s = input()
	ans = 0
	m = []
	for i in range(n):
		m.append(s[i])
	for k in range(1, n):
		if (n - k) % 2 == 0:
			for i in range(n):
				if s[(i + k) % n] == m[i]:
					continue
				elif s[(i + k) % n] < m[i]:
					ans = k
					for j in range(n):
						m[j] = s[(j + k) % n]
					break
				else:
					break
		else:
			for i in range(n):
				if i < n - k:
					if s[k + i] == m[i]:
						continue
					elif s[k + i] < m[i]:
						ans = k
						for j in range(n - k):
							m[j] = s[j + k]
						for j in range(n - k, n):
							m[j] = s[n - j - 1]
						break
					else:
						break
				elif m[i] == s[n - i - 1]:
					continue
				elif s[n - i - 1] < m[i]:
					ans = k
					for j in range(n - k):
						m[j] = s[j + k]
					for j in range(n - k, n):
						m[j] = s[n - j - 1]
					break
				else:
					break
	for num in m:
		print(num, end='')
	print()
	print(ans + 1)


for _ in range(int(input())):
	n = int(input())
	s = input()
	r = s[::-1]
	min_s = s
	ans = 1
	for k in range(2, 1 + n):
		tmp = s[k - 1:]
		if (n + k) % 2 == 1:
			tmp += s[:k - 1]
		else:
			tmp += r[n - k + 1:]
		if min_s > tmp:
			ans = k
			min_s = tmp
	print(min_s)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	t = II()
	for _ in range(t):
		n = II()
		s = SI()
		aa = [ord(c) for c in s]
		mn = min(aa)
		ii = []
		for (i, a) in enumerate(aa):
			if a == mn:
				ii.append(i)
		sk = []
		for i in ii:
			k = i + 1
			if n - k & 1:
				sk.append((aa[i:] + aa[:i], k))
			else:
				sk.append((aa[i:] + aa[:i][::-1], k))
		(anss, ansk) = min(sk)
		print(''.join((chr(a) for a in anss)))
		print(ansk)
main()


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input().rstrip()
	p = 200
	k = 1
	res = a
	ma = a[:]
	for i in range(n):
		if (n - i - 2) % 2 == 0:
			s = a[i + 1:] + a[:i + 1][::-1]
		else:
			s = a[i + 1:] + a[:i + 1]
		if s < ma:
			res = s
			ma = s[:]
			k = i + 2
	print(res)
	print(k)


def main():
	n = int(input())
	string = list(str(input()))
	index = 0
	res = ''.join(string)
	for i in range(1, n):
		string2 = ''
		if (i + 1) % 2 != n % 2:
			string2 = ''.join(string[i:n] + string[:i])
		else:
			string2 = ''.join(string[i:n] + string[i - 1::-1])
		if string2 < res:
			index = i
			res = string2
	print(res)
	print(index + 1)

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import math
t = int(input())
for itt in range(t):
	n = int(input())
	s = input().strip()
	arr = []
	for i in range(1, n + 1):
		if i == 1:
			arr.append([s, 1])
			continue
		if i == n:
			arr.append([s[::-1], n])
			continue
		xx = i - 1
		if i % 2 == 1:
			if n % 2 == 1:
				temp = s[xx:] + s[0:xx][::-1]
				arr.append([temp, i])
			else:
				temp = s[xx:] + s[0:xx]
				arr.append([temp, i])
		elif n % 2 == 1:
			xx = i - 1
			temp = s[xx:] + s[0:xx]
			arr.append([temp, i])
		else:
			temp = s[xx:] + s[0:xx][::-1]
			arr.append([temp, i])
	arr.sort(key=lambda item: item[0])
	print(arr[0][0])
	print(arr[0][1])


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin, tan

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
for _ in range(ii()):
	n = ii()
	a = lsi()
	b = a[:]
	p = 1
	for i in range(1, n):
		x = a[i:]
		z = a[:i]
		if not (n - i) % 2:
			x += z
		else:
			x += z[::-1]
		if x < b:
			b = x
			p = i + 1
	print(*b, sep='')
	print(p)


t = int(input())
for _ in range(t):
	n = int(input())
	S = input()
	ans = S
	ans_k = 1
	for k in range(1, n + 1):
		if (n - k) % 2 == 0:
			ans_ = S[k - 1:] + S[:k - 1][::-1]
		else:
			ans_ = S[k - 1:] + S[:k - 1]
		if ans_ < ans:
			ans = ans_
			ans_k = k
	print(ans)
	print(ans_k)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline().strip('\n'))
	st_input = list(stdin.readline().strip('\n'))
	ans = st_input[:]
	ans_k = 1
	for k in range(1, n + 1):
		s = st_input[:]
		for i in range(n - k + 1):
			s[i] = st_input[i + k - 1]
		for i in range(n - k + 1, n):
			if n % 2 == k % 2:
				s[i] = st_input[n - i - 1]
			else:
				s[i] = st_input[i - (n - k + 1)]
		if s < ans:
			ans = s
			ans_k = k
	for i in ans:
		print(i, end='')
	print()
	print(ans_k)


q = int(input())
for i in range(q):
	minn = 'z' * 5000
	n = int(input())
	s = input()
	for j in range(n):
		step = 1
		if (n - j) % 2 == 1:
			step = -1
		st = s[j:] + s[:j][::step]
		if st < minn:
			minn = st
			k = j + 1
	print(minn)
	print(k)


t = int(input())
while t > 0:
	n = int(input())
	s = input()
	mem = []
	lst = list(s)
	for i in range(0, n):
		if i == 0:
			mem.append([s[i:], i + 1])
		elif i < n - 1:
			if (n - i) % 2 == 0:
				mem.append([s[i:] + s[:i], i + 1])
			else:
				mem.append([s[i:] + s[i - 1::-1], i + 1])
		else:
			mem.append([s[-1::-1], n])
	mem.sort()
	print(mem[0][0])
	print(mem[0][1])
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	s = input()
	minn = min(s)
	smallest = s
	mink = 0
	for k in range(1, n):
		if s[k] == minn:
			if k % 2 == n % 2:
				maybe = s[k:] + s[:k]
			else:
				left = s[k:]
				right = s[:k][::-1]
				maybe = left + right
			if maybe < smallest:
				smallest = maybe
				mink = k
	mink += 1
	print(smallest)
	print(mink)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	mi = s
	index = 1
	for j in range(1, n):
		if (n + j + 1) % 2 == 0:
			s1 = s[j:] + s[0:j][::-1]
			if s1 < mi:
				mi = s1
				index = j + 1
		else:
			s1 = s[j:] + s[0:j]
			if s1 < mi:
				mi = s1
				index = j + 1
	print(mi)
	print(index)


from sys import stdin

def inp():
	return next((ss.rstrip() for ss in stdin))

def itg():
	return int(inp())

def mpint():
	return map(int, inp().split())
for case in range(itg()):
	n = itg()
	s = inp()
	min_char = min(s)
	kk = [i + 1 for i in range(n) if s[i] == min_char]
	results = []
	for k in kk:
		reverse = n - k + 1 & 1
		if not reverse:
			results.append((s[k - 1:] + s[:k - 1], k))
		else:
			results.append((s[k - 1:] + s[:k - 1][::-1], k))
	ans = min(results)
	print(ans[0])
	print(ans[1])


for _ in range(int(input())):
	a = input()
	s = input()
	lex = ['z']
	lexmax = 1
	lent = len(s)
	for i in range(1, len(s) + 1):
		if (lent - i + 1) % 2 == 0:
			u = s[:i - 1]
		else:
			u = s[:i - 1][::-1]
		temp = s[i - 1:] + u
		lex.append(temp)
		if i == 1:
			lexmax = i
		elif lex[lexmax] > lex[i]:
			lexmax = i
	print(lex[lexmax])
	print(lexmax)


from sys import stdin, stdout
Pi = lambda x: stdout.write(str(x) + '\n')
S = lambda x: x * (x + 1) // 2
R = lambda : stdin.readline()
Ri = lambda x: map(int, x.split())

def main():
	t = int(R())
	for i in range(t):
		n = int(R())
		s = R().strip('\n')
		v = [0] * 26
		for c in s:
			v[ord(c) - 97] += 1
		for i in range(26):
			if v[i]:
				if v[i] == n:
					Pi(s)
					Pi(1)
				else:
					ans = -1
					c = chr(i + 97)
					(tmp1, tmp2) = (s, '')
					if c == s[0]:
						ans = 1
					for i in range(n):
						if c == s[i] and i + 1 != n:
							dif = n - i
							if dif % 2 == 0:
								tmp2 = s[i:] + s[:i]
							else:
								cad = s[:i]
								tmp2 = s[i:] + cad[::-1]
							if tmp2 < tmp1:
								tmp1 = tmp2
								ans = i + 1
						elif c == s[i]:
							tmp2 = s[::-1]
							if tmp2 < tmp1:
								tmp1 = tmp2
								ans = n
					Pi(tmp1)
					Pi(ans)
				break
main()


T = int(input())
while T:
	T -= 1
	n = int(input())
	s = input()
	ret = s
	k = 1
	for i in range(1, n):
		if (n - i) % 2:
			t = s[i:] + s[0:i][::-1]
		else:
			t = s[i:] + s[0:i]
		if ret > t:
			ret = t
			k = i + 1
	t = s[::-1]
	if ret > t:
		ret = t
		k = n
	print(ret)
	print(k)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	tmp = a[0:]
	ans = -1
	for i in range(n):
		cnt = n - i
		if cnt % 2 == 0:
			if a[i:n] + a[0:i] < tmp:
				tmp = a[i:n] + a[0:i]
				ans = i
		elif a[i:n] + a[0:i][::-1] < tmp:
			tmp = a[i:n] + a[0:i][::-1]
			ans = i
	print(tmp)
	print(ans + 1)