#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
mt19937 rnd(51515);
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string mn = "";
    for (int i = 0; i < n; ++i) mn += 'z';
    int k = 1e9 + 7;
    for (int i = 0; i < n; ++i) {
      string c = s.substr(0, i);
      string b;
      if (i == n)
        b = "";
      else
        b = s.substr(i, n - i);
      if ((n - i) % 2 == 1) reverse(c.begin(), c.end());
      string g = b + c;
      if (mn >= g) {
        if (mn > g)
          k = i + 1;
        else
          k = min(k, i + 1);
        mn = g;
      }
    }
    cout << mn << '\n';
    cout << k << '\n';
  }
  return 0;
}
