#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
const long long p = 1e9 + 7;
;
long long fpow(long long n, long long k) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a) { return fpow(a, p - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string kq = s;
    int kq1 = 1;
    for (int k = 2; k <= n; k++) {
      string r = "";
      for (int i = k - 1; i <= n - 1; i++) r += s[i];
      if ((n - k + 1) % 2 == 1) {
        for (int i = k - 2; i >= 0; i--) r += s[i];
      } else {
        for (int i = 0; i <= k - 2; i++) r += s[i];
      }
      if (r < kq) {
        kq = r;
        kq1 = k;
      }
    }
    cout << kq << '\n' << kq1 << '\n';
  }
}
