#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, i, j, p, k;
  cin >> t;
  while (t--) {
    char n[5005], d[5005];
    cin >> x;
    cin >> n;
    strcpy(d, n);
    k = 1;
    for (i = 1; i < x; i++) {
      char m[5005] = "", ch[5005] = "";
      strncpy(m, n + i, x - i);
      strncpy(ch, n, i);
      if (i % 2 == (x - 1) % 2) {
        reverse(ch, ch + i);
      }
      strcat(m, ch);
      p = strcmp(m, d);
      if (p == -1) {
        strcpy(d, m);
        k = i + 1;
      }
    }
    cout << d << endl << k << endl;
  }
}
