#include <bits/stdc++.h>
using namespace std;
void solve_case() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<pair<string, int>> strs;
  strs.emplace_back(s, 1);
  for (int i = 2; i <= n; ++i) {
    string curr;
    int k = n - i + 1;
    if (k % 2 == 0) {
      for (int k = i - 1; k < n; ++k) {
        curr += s[k];
      }
      for (int j = 0; j < i - 1; ++j) {
        curr += s[j];
      }
    } else {
      for (int k = i - 1; k < n; ++k) {
        curr += s[k];
      }
      for (int j = i - 2; j >= 0; j--) {
        curr += s[j];
      }
    }
    strs.emplace_back(curr, i);
  }
  string curr;
  for (int l = n - 1; l >= 0; l--) {
    curr += s[l];
  }
  strs.emplace_back(curr, n);
  sort(((strs)).begin(), ((strs)).end());
  cout << strs[0].first << "\n" << strs[0].second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n = 1;
  cin >> n;
  while (n--) {
    solve_case();
  }
  return 0;
}
