#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 300009;
void swap(char *p, char *q) {
  char temp = *p;
  *p = *q;
  *q = temp;
  return;
}
long long int powxy(long long int x, long long int y) {
  if (y == 0) return 1;
  if (y % 2 == 1) return (x * powxy(x, y - 1)) % MOD;
  long long int t = powxy(x, y / 2) % MOD;
  return (t * t) % MOD;
}
vector<pair<int, int> > adj[N];
int dp[500005];
vector<int> ans[500001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int ans = 1;
    string s;
    long long int n;
    cin >> n >> s;
    string temp = s;
    for (int i = 0; i < n; i++) {
      if ((i + 1) % 2 != 0) {
        string q = s.substr(0, i);
        if ((n - i + 1) % 2 == 0) reverse(q.begin(), q.end());
        string p = s.substr(i, n - i) + q;
        if (p < temp) {
          temp = p;
          ans = i + 1;
        }
      } else {
        string q = s.substr(0, i);
        reverse(q.begin(), q.end());
        if ((n - i + 1) % 2 != 0) reverse(q.begin(), q.end());
        string p = s.substr(i, n - i) + q;
        if (p < temp) {
          temp = p;
          ans = i + 1;
        }
      }
    }
    cout << temp << "\n";
    cout << ans << "\n";
  }
}
