#include <bits/stdc++.h>
using namespace std;
int n, m, z, ans, t, flag;
string s;
inline int read() {
  int sum = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = (sum << 1) + (sum << 3) + c - '0';
    c = getchar();
  }
  return sum * f;
}
int main() {
  string x, y;
  int i, j;
  t = read();
  while (t--) {
    flag = 1;
    n = read();
    cin >> s;
    string aaa = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    for (i = 0; i < n; i++) {
      x = s.substr(i);
      y = s.substr(0, i);
      if ((n - i) % 2) reverse(y.begin(), y.end());
      x += y;
      if (aaa > x) {
        flag = i + 1;
        aaa = x;
      }
    }
    cout << aaa << endl << flag << endl;
  }
  return 0;
}
