#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> tmp, ans;
    int mn = 0x3f3f3f3f;
    for (int i = int(0); i < int(n); i++) mn = min(mn, s[i] - 'a');
    for (int i = int(0); i < int(n); i++)
      if (s[i] - 'a' == mn) tmp.push_back(i);
    ans = tmp;
    for (int i = int(1); i < int(n); i++) {
      ans = tmp;
      if (ans.size() == 1) break;
      mn = 0x3f3f3f3f;
      for (int j = int(0); j < int(ans.size()); j++) {
        int ind = ans[j] + i;
        int z = 0;
        if (ind >= n) {
          z = ind % n;
          if (n % 2 == (ans[j] + 1) % 2)
            ind = ans[j] - 1 - z;
          else
            ind = z;
        }
        mn = min(mn, s[ind] - 'a');
      }
      tmp.clear();
      for (int j = int(0); j < int(ans.size()); j++) {
        int ind = ans[j] + i;
        int z = 0;
        if (ind >= n) {
          z = ind % n;
          if (n % 2 == (ans[j] + 1) % 2)
            ind = ans[j] - 1 - z;
          else
            ind = z;
        }
        if (mn == s[ind] - 'a') tmp.push_back(ans[j]);
      }
    }
    string p = "";
    int xx = ans[0];
    for (int i = int(xx); i < int(n); i++) p += s[i];
    if (n % 2 == (xx + 1) % 2) {
      for (int j = int(xx) - 1; j >= int(0); j--) p += s[j];
    } else {
      for (int j = int(0); j < int(xx); j++) p += s[j];
    }
    xx++;
    cout << p << '\n' << xx << '\n';
  }
  return 0;
}
