#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<string, long long> > v;
    for (long long k = 0; k < n - 1; k++) {
      string t;
      for (long long j = k; j < n; j++) t += s[j];
      if ((n - k - 1) % 2 != 0)
        for (long long j = 0; j < k; j++) t += s[j];
      else {
        for (long long j = k - 1; j >= 0; j--) t += s[j];
      }
      v.push_back({t, k + 1});
    }
    reverse(s.begin(), s.end());
    v.push_back({s, n});
    stable_sort(v.begin(), v.end());
    cout << v[0].first << "\n";
    cout << v[0].second << "\n";
  }
}
