#include <bits/stdc++.h>
using namespace std;
string modification(std::string yo, int n, int k) {
  string result_prefix = yo.substr(k - 1, n - k + 1);
  string result_suffix = yo.substr(0, k - 1);
  if (n % 2 == k % 2) {
    reverse(result_suffix.begin(), result_suffix.end());
  }
  return result_prefix + result_suffix;
}
int main() {
  std::string yo;
  int t;
  std::cin >> t;
  ;
  while (t--) {
    int n;
    std::cin >> n;
    ;
    std::cin >> yo;
    std::string low_str = modification(yo, n, 1);
    int k_for_low_str = 1;
    std::string temp;
    for (int i = 2; i <= n; i++) {
      temp = modification(yo, n, i);
      if (temp < low_str) {
        low_str = temp;
        k_for_low_str = i;
      }
    }
    std::cout << low_str << '\n' << k_for_low_str << '\n';
  }
}
