#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  int n;
  string rakh1, rakh2, rakh, ch, ch_min;
  while (test--) {
    cin >> n;
    cin >> ch;
    ch_min = ch;
    int pos = 1;
    for (int i = 1; i < (n - 1); i++) {
      rakh1 = ch.substr(0, i);
      rakh2 = ch.substr(i, n - 1);
      if ((n % 2 != 0 && i % 2 == 0) || (n % 2 == 0 && i % 2 != 0))
        reverse(rakh1.begin(), rakh1.end());
      rakh = rakh2 + rakh1;
      if (ch_min > rakh) {
        pos = i + 1;
        ch_min = rakh;
      }
    }
    reverse(ch.begin(), ch.end());
    if (ch_min > ch) {
      pos = n;
      ch_min = ch;
    }
    cout << ch_min << endl;
    cout << pos << endl;
  }
  return 0;
}
