#include <bits/stdc++.h>
using namespace std;
int t, n, k;
string sequence;
string modify(string &s, int n, int k) {
  string left = s.substr(k - 1, n - k + 1);
  string right = s.substr(0, k - 1);
  if (n % 2 == k % 2) {
    reverse(right.begin(), right.end());
  }
  return left + right;
}
int main() {
  cin >> t;
  for (int test = 1; test <= t; test++) {
    cin >> n >> sequence;
    string aux = modify(sequence, n, 1);
    int minK = 1;
    for (int i = 2; i <= n; i++) {
      string auxTemp = modify(sequence, n, i);
      if (auxTemp < aux) {
        aux = auxTemp;
        minK = i;
      }
    }
    cout << aux << '\n' << minK << '\n';
  }
  return 0;
}
