#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    string k;
    k = s;
    sort(k.begin(), k.end());
    if (k == s) {
      cout << s << "\n";
      cout << 1 << "\n";
    } else {
      char mn = 'z';
      for (long long i = 0; i < n; i++) {
        if (s[i] <= mn) {
          mn = s[i];
        }
      }
      string ans = s;
      long long index = 1;
      for (long long i = 1; i < n; i++) {
        if (s[i] == mn) {
          string p = s.substr(i, n - 1);
          string q = s.substr(0, i);
          if ((n % 2) != (i % 2)) {
            reverse(q.begin(), q.end());
          }
          string j = p + q;
          if (i == n - 1) {
            j = s;
            reverse(j.begin(), j.end());
          }
          if (j < ans) {
            index = i + 1;
            ans = j;
          }
        }
      }
      cout << ans << "\n" << index << "\n";
    }
  }
  return 0;
}
