#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    string s;
    cin >> s;
    string res = s;
    int times = 1;
    string t;
    string t1, t2;
    for (int i = 2; i < n; ++i) {
      t1 = s.substr(i - 1);
      t2 = s.substr(0, i - 1);
      if ((n - i + 1) % 2 == 1) reverse(t2.begin(), t2.end());
      t = t1 + t2;
      if (t < res) {
        res = t;
        times = i;
      }
    }
    t = s;
    reverse(t.begin(), t.end());
    if (t < res) {
      times = n;
      res = t;
    }
    cout << res << endl;
    printf("%d\n", times);
  }
  return 0;
}
