#include <bits/stdc++.h>
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);
const long long mod = 998244353;
const long long maxn = 2000001;
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long modOp(long long a, long long b) {
  long long c = a % b;
  if (c < 0) c += b;
  return c;
}
void solve() {
  long long n, m, an = 1;
  cin >> n;
  string s, ss, sk, ans;
  cin >> s;
  ans = s;
  for (int i = 2; i <= n - 1; i++) {
    ss = s.substr(0, i - 1);
    sk = s.substr(i - 1);
    if ((n - i + 1) % 2 != 0) reverse(ss.begin(), ss.end());
    sk += ss;
    if (sk < ans) {
      ans = sk;
      an = i;
    }
  }
  reverse(s.begin(), s.end());
  if (s < ans) {
    ans = s;
    an = n;
  }
  cout << ans << "\n";
  cout << an << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int test;
  cin >> test;
  while (test--) solve();
  return 0;
}
