#include <bits/stdc++.h>
using namespace std;
char s[5005], t[5005], r[5005];
int T, n, ans;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%s", &n, t);
    strcpy(r, t);
    reverse(r, r + n);
    ans = n;
    for (int i = n - 1; i > 0; i--) {
      strcpy(s, t);
      rotate(s, s + i - 1, s + n);
      if (n - i + 1 & 1) reverse(s + n - i + 1, s + n);
      if (strcmp(s, r) <= 0) strcpy(r, s), ans = i;
    }
    printf("%s\n%d\n", r, ans);
  }
  return 0;
}
