#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = s;
    int c = 1;
    for (int i = 2; i <= n; i++) {
      string str1;
      for (int j = i - 1; j < n; j++) {
        str1 += s[j];
      }
      string str2;
      for (int j = 0; j < i - 1; j++) {
        str2 += s[j];
      }
      if (str1.length() & 1) {
        reverse(str2.begin(), str2.end());
      }
      str1 = str1 + str2;
      if (str1 < ans) {
        ans = str1;
        c = i;
      }
    }
    cout << ans << "\n" << c << "\n";
  }
  return 0;
}
