#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    s += s;
    string mo = s, me = s;
    int o = 0, e = 0;
    if (n % 2 == 0) {
      for (int i = 0; i < n; i += 2) {
        if (s.substr(i, n) < me) me = s.substr(i, n), e = i + 1;
      }
      for (int i = 1; i < n; i += 2) {
        string ns = s.substr(n, i);
        reverse(ns.begin(), ns.end());
        ns = s.substr(i, n - i) + ns;
        if (ns < mo) mo = ns, o = i + 1;
      }
    }
    if (n % 2 == 1) {
      for (int i = 1; i < n; i += 2) {
        if (s.substr(i, n) < me) me = s.substr(i, n), e = i + 1;
      }
      for (int i = 0; i < n; i += 2) {
        string ns = s.substr(n, i);
        reverse(ns.begin(), ns.end());
        ns = s.substr(i, n - i) + ns;
        if (ns < mo) mo = ns, o = i + 1;
      }
    }
    if (me < mo) {
      cout << me << "\n";
      cout << e << "\n";
    } else if (me == mo) {
      cout << me << "\n";
      cout << min(e, o) << "\n";
    } else {
      cout << mo << "\n";
      cout << o << "\n";
    }
  }
}
