#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d, i, j, k, arr1[8005], arr2[8005], l;
  char s1[5008];
  scanf("%lld", &a);
  for (k = 1; k <= a; k++) {
    scanf("%lld", &b);
    vector<pair<string, int> > mp;
    scanf("%s", &s1);
    for (i = 0; i < b; i++) {
      c = -1;
      d = 0;
      string ck;
      for (j = i; j < b; j++) {
        ck += s1[j];
        d++;
      }
      if (d % 2 == 0) {
        for (l = 0; l < i; l++) ck += s1[l];
      } else {
        for (l = i - 1; l >= 0; l--) {
          ck += s1[l];
        }
      }
      mp.push_back(make_pair(ck, i + 1));
    }
    sort(mp.begin(), mp.end());
    cout << mp[0].first << "\n" << mp[0].second << endl;
  }
  return 0;
}
