#include <bits/stdc++.h>
using namespace std;
enum STATE { IN, OUT, BOUNDRY };
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
int lx[] = {2, 2, -1, 1, -2, -2, -1, 1};
int ly[] = {-1, 1, 2, 2, 1, -1, -2, -2};
const long double eps = 1e-3;
const int N = 2e5 + 50, M = 4e4 + 10, mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  long long t = gcd(a, b);
  return t ? (a / t * b) : 0;
}
int main() {
  fast_in_out();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string str = s;
    int k = 1;
    for (int i = 1; i < n; i++) {
      string str2;
      for (int j = i; j < n; j++) str2 += s[j];
      string ss;
      for (int j = 0; j < i; j++) ss += s[j];
      if (((i + 1) & 1) == (n & 1)) reverse(ss.begin(), ss.end());
      str2 += ss;
      if (str2 < str) str = str2, k = i + 1;
    }
    cout << str << "\n" << k << '\n';
  }
  return 0;
}
