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