#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k = 1;
  cin >> n;
  string s, temp = "", ans = "", temp2 = "";
  cin >> s;
  ans = s;
  for (int i = 1; i < n; ++i) {
    temp = s.substr(i);
    temp2 = s.substr(0, i);
    if ((n - i) & 1) {
      reverse(temp2.begin(), temp2.end());
    }
    temp = temp + temp2;
    if (temp < ans) ans = temp, k = i + 1;
  }
  cout << ans << "\n";
  cout << k << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
}
