#include <bits/stdc++.h>
using namespace std;
string modifications(string& s, int n, int k) {
  string prefix = s.substr(k - 1, n - k + 1);
  string suffix = s.substr(0, k - 1);
  if (n % 2 == k % 2) reverse(suffix.begin(), suffix.end());
  return prefix + suffix;
}
void solve() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  string ans;
  string t;
  ans = modifications(str, n, 1);
  int min_k = 1;
  for (int k = 2; k <= n; k++) {
    t = modifications(str, n, k);
    if (t < ans) {
      ans = t;
      min_k = k;
    }
  }
  cout << ans << " " << endl;
  cout << min_k << " " << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
