#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    string s;
    cin >> s;
    string good = s;
    int mk = 1;
    for (int k = 1; k <= n; k++) {
      string tmp;
      tmp += s.substr(k - 1);
      string ttmp = s.substr(0, k - 1);
      if ((n - k) % 2 == 0) {
        reverse(ttmp.begin(), ttmp.end());
      }
      tmp += ttmp;
      if (good > tmp) {
        mk = k;
        good = tmp;
      }
    }
    cout << good << endl << mk << endl;
  }
}
