#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s, s1;
    cin >> s;
    s1 = s;
    vector<long long> v;
    sort(s1.begin(), s1.end());
    long long l = s.length();
    for (long long i = 0; i < l; i++) {
      if (s[i] == s1[0]) v.push_back(i);
    }
    vector<string> s2(v.size());
    for (long long i = 0; i < v.size(); i++) {
      if (l % 2) {
        if ((v[i] + 1) % 2) {
          for (long long j = v[i]; j < n; j++) s2[i].push_back(s[j]);
          for (long long j = v[i] - 1; j >= 0; j--) s2[i].push_back(s[j]);
        } else {
          string s3 = s;
          s3.append(s);
          for (long long j = v[i]; j < v[i] + l; j++) s2[i].push_back(s3[j]);
        }
      } else {
        if ((v[i] + 1) % 2) {
          string s3 = s;
          s3.append(s);
          for (long long j = v[i]; j < v[i] + l; j++) s2[i].push_back(s3[j]);
        } else {
          for (long long j = v[i]; j < n; j++) s2[i].push_back(s[j]);
          for (long long j = v[i] - 1; j >= 0; j--) s2[i].push_back(s[j]);
        }
      }
    }
    vector<pair<string, long long>> v1;
    for (long long i = 0; i < v.size(); i++) v1.push_back(make_pair(s2[i], i));
    sort(v1.begin(), v1.end());
    cout << v1[0].first << endl;
    cout << v[v1[0].second] + 1 << endl;
  }
}
