#include <bits/stdc++.h>
using namespace std;
string s, temp, c;
string work(int l, int r) { return s.substr(l, r + 1); }
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    temp = s;
    int ans = 1;
    for (int k = 2; k <= n; k++) {
      string a = work(0, k - 2);
      string b = work(k - 1, n - 1);
      if ((n - k + 1) % 2 == 1) {
        int ss = a.size();
        for (int i = 0; i < (ss + 1) / 2; i++) {
          char t = a[i];
          a[i] = a[ss - i - 1];
          a[ss - i - 1] = t;
        }
      }
      c = b + a;
      if (c < temp) {
        temp = c, ans = k;
      }
    }
    cout << temp << endl;
    cout << ans << endl;
  }
}
