#include <bits/stdc++.h>
using namespace std;
long long int MOD = (1e9 + 7);
long long int nCr[1001][1001];
void Cnr() {
  long long int i, j;
  for (i = 1; i <= 1000; i++) nCr[i][0] = 1;
  for (i = 0; i <= 1000; i++) nCr[0][i] = 0;
  nCr[0][0] = 1;
  for (i = 1; i <= 1000; i++) {
    for (j = 1; j <= i; j++)
      nCr[i][j] = (nCr[i - 1][j - 1] % MOD + nCr[i - 1][j] % MOD) % MOD;
  }
}
long long int power(long long int a, long long int x) {
  if (a == 0) return 0;
  if (a == 1) return 1;
  if (x == 0) return 1;
  return a * power(a, x - 1);
}
bool comp(pair<long long int, long long int> p1,
          pair<long long int, long long int> p2) {
  if (p1.first > p2.first) return true;
  if (p1.first < p2.first) return false;
  if (p1.second < p2.second) return true;
  return false;
}
void solve() {
  long long int n, i, j;
  cin >> n;
  string s;
  cin >> s;
  if (n % 2 == 0) {
    vector<pair<string, long long int> > v;
    string temp;
    long long int k;
    for (k = 1; k <= n; k++) {
      if (k % 2 == 0) {
        temp = s.substr(k - 1);
        string s2 = s.substr(0, k - 1);
        reverse(s2.begin(), s2.end());
        temp = temp + s2;
        v.push_back(make_pair(temp, k));
      } else {
        temp = s.substr(k - 1);
        string s2 = s.substr(0, k - 1);
        temp = temp + s2;
        v.push_back(make_pair(temp, k));
      }
    }
    sort(v.begin(), v.end());
    cout << v[0].first << endl;
    cout << v[0].second << endl;
  } else {
    vector<pair<string, long long int> > v;
    string temp;
    long long int k;
    for (k = 1; k <= n; k++) {
      if (k % 2 == 1) {
        temp = s.substr(k - 1);
        string s2 = s.substr(0, k - 1);
        reverse(s2.begin(), s2.end());
        temp = temp + s2;
        v.push_back(make_pair(temp, k));
      } else {
        temp = s.substr(k - 1);
        string s2 = s.substr(0, k - 1);
        temp = temp + s2;
        v.push_back(make_pair(temp, k));
      }
    }
    sort(v.begin(), v.end());
    cout << v[0].first << endl;
    cout << v[0].second << endl;
  }
}
int32_t main() {
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
