#include <bits/stdc++.h>
using namespace std;
void printarray(int* arr, int start, int end) {
  printf("Printing the array from %d to %d \n", start, end);
  for (int i = start; i <= end; i++) {
    printf("%d ", arr[i]);
  }
  printf("\nDone printing the array\n");
}
int n;
string s;
int a[100005];
bool lexi(string s1, string s2) {
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] < s2[i]) {
      return 1;
    } else if (s1[i] > s2[i]) {
      return 0;
    }
  }
  return 0;
}
void input() {
  scanf("%d", &n);
  cin >> s;
}
void solve() {
  vector<string> vec;
  int index = 0;
  string temp, ans;
  for (int k = 1; k <= n; k++) {
    if ((n - k) % 2 == 0) {
      temp = s.substr(0, k - 1);
      reverse(temp.begin(), temp.end());
      vec.push_back(s.substr(k - 1) + temp);
    } else {
      vec.push_back(s.substr(k - 1) + s.substr(0, k - 1));
    }
  }
  ans = s;
  for (int i = 0; i < vec.size(); i++) {
    if (lexi(vec[i], ans)) {
      ans = vec[i];
      index = i;
    }
  }
  cout << ans << endl;
  printf("%d\n", index + 1);
}
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    input();
    solve();
  }
  return 0;
}
