#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e6 + 10;
vector<int> v[maxi];
string s;
int n, m;
int a[maxi];
void solve() {
  cin >> n;
  cin >> s;
  string ans = s;
  int poz = 1;
  for (int i = 2; i <= n; i++) {
    string s1 = s.substr(i - 1, s.size() - i + 1);
    string s2 = s.substr(0, i - 1);
    if ((n - i) % 2 == 0) reverse(s2.begin(), s2.end());
    s1 = s1 + s2;
    if (ans > s1) {
      ans = s1;
      poz = i;
    }
  }
  cout << ans << endl;
  cout << poz << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
