#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1999999999999999997;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v;
    int mn = 28;
    for (int i = 0; i < n; i++) {
      if (mn >= (s[i] - 'a')) mn = s[i] - 'a';
    }
    for (int i = 0; i < n; i++) {
      if (s[i] - 'a' == mn) {
        v.push_back(i);
      }
    }
    int k = 1;
    string t = s;
    for (int i = 0; i < (int)v.size(); i++) {
      if (v[i] != 0) {
        string temp;
        int c = n - v[i];
        for (int j = v[i]; j < n; j++) {
          temp.push_back(s[j]);
        }
        if (c & 1) {
          for (int j = v[i] - 1; j >= 0; j--) temp.push_back(s[j]);
        } else {
          for (int j = 0; j < v[i]; j++) temp.push_back(s[j]);
        }
        if (temp < t) {
          k = v[i] + 1;
          t = temp;
        }
      }
    }
    cout << t;
    cout << endl;
    cout << k << endl;
  }
}
