#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    string second;
    cin >> n >> second;
    pair<string, int> ans(second, 1);
    deque<char> l, r;
    for (char c : second) l.push_back(c);
    for (int i = 2; i <= n; i++) {
      r.push_back(l.front());
      l.pop_front();
      if (i % 2 == n % 2) reverse(r.begin(), r.end());
      string t;
      for (char c : l) t += c;
      for (char c : r) t += c;
      if (i % 2 == n % 2) reverse(r.begin(), r.end());
      ans = min(ans, make_pair(t, i));
    }
    cout << ans.first << '\n' << ans.second << '\n';
  }
  exit(0);
}
