#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  long long t;
  cin >> t;
  for (long long cc = 0; cc < t; cc++) {
    string s;
    long long n;
    cin >> n;
    cin >> s;
    pair<string, long long> tt = {s, 1};
    for (long long k = 2; k <= s.size(); k++) {
      string cur;
      for (long long i = k - 1; i < s.size(); i++) {
        cur += s[i];
      }
      if ((s.size() - k + 1) % 2 == 0) {
        for (long long i = 0; i < k - 1; i++) {
          cur += s[i];
        }
      } else {
        for (long long i = k - 2; i >= 0; i--) {
          cur += s[i];
        }
      }
      tt = min(tt, {cur, k});
    }
    cout << tt.first << '\n' << tt.second << '\n';
  }
  return 0;
}
