#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const int M = 1e6;
const long long INF = (long long)(1e18);
const int inf = 1e9;
const long long MOD = 1000000007LL;
string get(string s, int k) {
  if (k == s.size()) {
    reverse(s.begin(), s.end());
    return s;
  }
  int help = s.size() - k + 1;
  string l = s.substr(0, k - 1);
  ;
  string r = s.substr(k - 1, string::npos);
  if (help % 2) reverse(l.begin(), l.end());
  return r + l;
}
void solve() {
  int n;
  string s;
  cin >> n >> s;
  string ans = s;
  int res = 1;
  for (int k = 2; k <= n; k++) {
    string cand = get(s, k);
    if (cand < ans) {
      ans = cand;
      res = k;
    }
  }
  cout << ans << "\n" << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
