#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long ans = 1;
    string p = s;
    for (long long i = 1; i < n; i++) {
      string g = "";
      for (long long j = i; j < n; j++) g += s[j];
      if ((n - i) & 1) {
        for (long long j = i - 1; j >= 0; j--) g += s[j];
      } else {
        for (long long j = 0; j < i; j++) g += s[j];
      }
      if (g < p) {
        ans = i + 1;
        p = g;
      }
    }
    cout << p << "\n";
    cout << ans << "\n";
  }
  return 0;
}
