#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long inf2 = 1e9;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  };
  int t;
  cin >> t;
  while (t--) {
    int n, i, j, k = 1;
    cin >> n;
    string second, ans;
    cin >> second;
    ans = second;
    for (i = 0; i < n; i++) {
      string s1 = "", s2 = "";
      int cnt = 0;
      for (j = i; j < n; j++) {
        s1 += second[j];
        cnt++;
      }
      for (j = 0; j < i; j++) {
        s2 += second[j];
      }
      if (cnt % 2) reverse(s2.begin(), s2.end());
      s1 += s2;
      if (s1 < ans) {
        ans = s1;
        k = i + 1;
      }
    }
    cout << ans << '\n' << k << '\n';
  }
  return 0;
}
