#include <bits/stdc++.h>
using namespace std;
long long INF = 999999999999999;
string getStr(string s, int k) {
  long long n = s.length();
  vector<long long> ni(n);
  for (int i = k - 1; i < n; i++) {
    ni[i] = i - (k - 1);
  }
  for (int i = 0; i < k - 1; i++) {
    if ((n - k + 1) % 2) {
      ni[i] = n - 1 - i;
    } else
      ni[i] = n - k + i + 1;
  }
  string s1 = "";
  for (int i = 0; i < n; i++) {
    s1 += 'a';
  }
  for (int i = 0; i < n; i++) {
    s1[ni[i]] = s[i];
  }
  return s1;
}
bool mnn(string s1, string s2) {
  long long n = s1.length();
  for (int i = 0; i < n; i++) {
    if (s1[i] < s2[i]) return true;
    if (s1[i] > s2[i]) return false;
  }
  return false;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  char mc = 'z';
  string mn = s;
  long long ans = 1;
  for (int k = 1; k <= n; k++) {
    string s1 = getStr(s, k);
    if (mnn(s1, mn)) {
      mn = s1;
      ans = k;
    }
  }
  cout << mn << "\n" << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
}
