#include <bits/stdc++.h>
using namespace std;
char a[50005], b[50005], c[50005];
vector<int> mp[27];
int main() {
  int t;
  while (scanf("%d", &t) != EOF) {
    while (t--) {
      int n, m = 1, h, g;
      scanf("%d", &n);
      scanf("%s", a + 1);
      for (int i = 1; i <= n; i++) {
        mp[a[i] - 'a' + 1].push_back(i);
      }
      for (int i = 1; i < 27; i++) {
        if (mp[i].size() != 0) {
          h = i;
          break;
        }
      }
      memset(c, 0, sizeof(c));
      memset(b, 0, sizeof(b));
      strcpy(c + 1, a + 1);
      for (int i = 0; i < mp[h].size(); i++) {
        g = 0;
        for (int j = mp[h][i]; j <= n; j++) {
          b[++g] = c[j];
        }
        if ((n - mp[h][i] + 1) % 2 == 1) {
          for (int j = mp[h][i] - 1; j >= 1; j--) {
            b[++g] = c[j];
          }
        } else {
          for (int j = 1; j < mp[h][i]; j++) {
            b[++g] = c[j];
          }
        }
        if (strcmp(a + 1, b + 1) > 0) {
          strcpy(a + 1, b + 1);
          m = mp[h][i];
        }
      }
      for (int i = 0; i < 27; i++) mp[i].clear();
      printf("%s\n", a + 1);
      printf("%d\n", m);
    }
  }
  return 0;
}
