#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 5;
string modif(string &s, int n, int k) {
  string str_prefix = s.substr(k - 1, n - k + 1);
  string str_suffix = s.substr(0, k - 1);
  if (n % 2 == k % 2) {
    reverse(str_suffix.begin(), str_suffix.end());
  }
  return str_prefix + str_suffix;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = s;
    int kk = 1;
    for (int i = 2; i <= n; i++) {
      string tmp = modif(s, n, i);
      if (tmp < ans) {
        ans = tmp;
        kk = i;
      }
    }
    cout << ans << "\n" << kk << "\n";
  }
  return 0;
}
