#include <bits/stdc++.h>
using namespace std;
const static int MAXN = 5e3 + 50;
string str;
inline string change(int len, int k) {
  string t;
  for (int i = k - 1; i < len; ++i) t += str[i];
  if ((len - k + 1) % 2 == 0) {
    for (int i = 0; i <= k - 2; ++i) t += str[i];
  } else {
    for (int i = k - 2; i >= 0; --i) t += str[i];
  }
  return t;
}
void solve() {
  str.clear();
  int len, mink = 1;
  cin >> len >> str;
  string mint = str;
  for (int i = 0; i < len; ++i) {
    string t = change(len, i + 1);
    if (t < mint) {
      mint = t;
      mink = i + 1;
    }
  }
  cout << mint << endl << mink << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  for (int i = 1; i <= T; ++i) solve();
  return 0;
}
