#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<string, int> > v;
    v.push_back(make_pair(s, 1));
    for (int i = 2; i < n + 1; i++) {
      string temp = s.substr(i - 1, n - i + 1);
      string temp1 = s.substr(0, i - 1);
      if (i % 2 == n % 2) reverse(temp1.begin(), temp1.end());
      temp = temp + temp1;
      v.push_back(make_pair(temp, i));
    }
    sort(v.begin(), v.end());
    cout << v[0].first << endl;
    cout << v[0].second << endl;
  }
}
