#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s, t, part_mod, orig;
    cin >> s;
    t = s;
    int K = 1;
    for (int k = 2; k <= n; k++) {
      part_mod = s.substr(0, k - 1);
      orig = s.substr(k - 1);
      if ((n - k + 1) % 2) {
        reverse(part_mod.begin(), part_mod.end());
      }
      orig += part_mod;
      if (orig < t) {
        t = orig;
        K = k;
      }
    }
    cout << t << "\n" << K << "\n";
  }
  return 0;
}
