#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int cases;
  cin >> cases;
  while (cases--) {
    int k, tmp;
    string s;
    cin >> n;
    cin >> s;
    string best = s;
    int bestk = 100000;
    for (int i = n; i >= 0; i--) {
      string reverse_k = s.substr(0, i);
      string starts = s.substr(i, n);
      if ((n - i) % 2 == 1) std::reverse(reverse_k.begin(), reverse_k.end());
      string current = starts + reverse_k;
      if (current <= best) {
        best = current;
        bestk = i;
      }
    }
    cout << best << endl;
    cout << bestk + 1 << endl;
  }
  return 0;
}
