#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")
using namespace std;
const long long INF = 1e18;
const long long NINF = -1e18;
const int inf = 1e9 + 5;
const int ninf = -(1e9 + 5);
const int mod = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
string modify(int n, int k, string second) {
  string prefix = second.substr(k - 1, n - k + 1);
  string suffix = second.substr(0, k - 1);
  if (n % 2 == k % 2) {
    reverse(suffix.begin(), suffix.end());
  }
  string done = prefix + suffix;
  return done;
}
int main() {
  int t;
  cin >> t;
  for (int q = 0; q < t; q++) {
    int n;
    cin >> n;
    string second;
    cin >> second;
    string ans = second;
    int minK = 1;
    for (int i = 2; i <= n; i++) {
      string test = modify(n, i, second);
      if (test < ans) {
        ans = test;
        minK = i;
      }
    }
    cout << ans << "\n";
    cout << minK << "\n";
  }
  return 0;
}
