#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int N = 5010;
char s[N], t[N], p[N];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    for (int i = 1; i <= n; ++i) {
      t[i] = p[i] = s[i];
    }
    int ans = 1;
    for (int ret = 2; ret <= n; ++ret) {
      for (int i = 1; i <= n - ret + 1; ++i) {
        p[i] = s[i + ret - 1];
      }
      if ((n - ret + 1) % 2 == 0) {
        for (int i = n - ret + 2; i <= n; ++i) {
          p[i] = s[i - (n - ret + 1)];
        }
      } else {
        for (int i = n - ret + 2; i <= n; ++i) {
          p[i] = s[ret - (i - (n - ret + 1))];
        }
      }
      bool flag = false;
      for (int i = 1; i <= n; ++i) {
        if (p[i] == t[i]) continue;
        if (p[i] < t[i]) {
          flag = true;
          break;
        } else
          break;
      }
      if (flag == true) {
        ans = ret;
        for (int i = 1; i <= n; ++i) {
          t[i] = p[i];
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      putchar(t[i]);
    }
    puts("");
    printf("%d\n", ans);
  }
  return 0;
}
