#include <bits/stdc++.h>
using namespace std;
string modified(string &s, int n, int k) {
  string sp = s.substr(k - 1, n - k + 1);
  string ss = s.substr(0, k - 1);
  if (n % 2 == k % 2) reverse(ss.begin(), ss.end());
  return sp + ss;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s, temp;
    cin >> s;
    string bs = modified(s, n, 1);
    int bk = 1, k;
    for (k = 2; k <= n; k++) {
      temp = modified(s, n, k);
      if (temp < bs) {
        bs = temp;
        bk = k;
      }
    }
    cout << bs << "\n" << bk << "\n";
  }
}
