#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T MIN(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T, typename... Args>
inline T MIN(const T &a, const T &b, Args... args) {
  return MIN(MIN(a, b), args...);
}
template <typename T, typename... Args>
inline T MAX(const T &a, const T &b, Args... args) {
  return MAX(MAX(a, b), args...);
}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    string s;
    cin >> n >> s;
    string res = s;
    int p = 1;
    for (int i = 1; i <= n; i++) {
      string t1 = s.substr(i - 1), t2 = s.substr(0, i - 1);
      if ((n - i) % 2 == 0) reverse(t2.begin(), t2.end());
      if (res > t1 + t2) res = t1 + t2, p = i;
    }
    cout << res << '\n' << p << '\n';
  }
  return 0;
}
