#include <bits/stdc++.h>
using namespace std;
bool mycompare(pair<string, int> p1, pair<string, int> p2) {
  if (p1.first == p2.first) {
    return p1.second < p2.second;
  }
  return p1.first < p2.first;
}
int main() {
  int t, j;
  cin >> t;
  for (j = 0; j < t; j = j + 1) {
    int n, i, count = 0;
    cin >> n;
    int a[n + 1];
    map<int, int> m;
    string s, v1, v2, v;
    cin >> s;
    for (i = 0; i < n; i = i + 1) {
      a[i] = s[i];
      m[a[i]] = m[a[i]] + 1;
    }
    sort(a, a + n);
    char x = (char)a[0];
    pair<string, int> p[m[a[0]] + 1];
    for (i = 0; i < n; i = i + 1) {
      if (s[i] == x) {
        v1 = s.substr(0, i);
        if ((((i + 1) % 2 == 1) && ((n - i - 1) % 2 == 0)) ||
            (((i + 1) % 2 == 0) && ((n - i - 1) % 2 == 0))) {
          reverse(v1.begin(), v1.end());
        }
        v2 = s.substr(i, n - i);
        v = v2 + v1;
        p[count].first = v;
        p[count].second = i;
        count = count + 1;
      }
    }
    sort(p, p + count, mycompare);
    cout << p[0].first << endl;
    cout << p[0].second + 1 << endl;
  }
}
