#include <bits/stdc++.h>
using namespace std;
string s;
struct node {
  string c;
  int k;
} a[5005];
bool cmp(node a, node b) {
  if (a.c == b.c) return a.k < b.k;
  return a.c < b.c;
}
int main() {
  int t;
  while (cin >> t) {
    while (t--) {
      int len;
      cin >> len >> s;
      a[0].c = s, a[0].k = 1;
      for (int i = 1; i < len; i++) {
        string q = "";
        for (int j = i; j < len; j++) {
          q += s[j];
        }
        if ((i + 1) % 2 == 0 && len % 2 == 0 ||
            (i + 1) % 2 == 1 && len % 2 == 1)
          for (int j = i - 1; j >= 0; j--) q += s[j];
        else
          for (int j = 0; j < i; j++) q += s[j];
        a[i].c = q, a[i].k = i + 1;
      }
      sort(a, a + len, cmp);
      cout << a[0].c << endl << a[0].k << endl;
    }
  }
  return 0;
}
