#include <bits/stdc++.h>
using namespace std;
string s;
struct st {
  string stt, ans;
  int k;
} sub[5005];
int T, n;
bool cmp(st a, st b) {
  if (a.ans < b.ans) return true;
  if (a.ans > b.ans) return false;
  return a.k < b.k;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    cin >> s;
    for (int i = 0; i < n; ++i) {
      sub[i].ans = s;
      sub[i].k = i + 1;
      sub[i].stt = s.substr(0, i);
      if ((sub[i].k % 2) == (n % 2))
        reverse(sub[i].stt.begin(), sub[i].stt.end());
      sub[i].ans += sub[i].stt;
      sub[i].ans.erase(0, i);
    }
    sort(sub, sub + n, cmp);
    cout << sub[0].ans << endl << sub[0].k << endl;
  }
  return 0;
}
