#include <bits/stdc++.h>
using namespace std;
bool comp(queue<char> G, queue<char> H) {
  if (G.size() > H.size()) swap(G, H);
  long long F = G.size();
  for (long long i = 0; i < (F); ++i) {
    char g = G.front(), h = H.front();
    G.pop();
    H.pop();
    if (g < h) {
      return true;
    } else if (g > h) {
      return false;
    }
  }
  return true;
}
signed main() {
  long long N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  long long e = 1;
  for (long long k = 0; k < (K - 1); ++k) {
    string U;
    queue<char> O, P;
    for (long long i = 0; i < (N); ++i) {
      O.push(S[i]);
    }
    P = O;
    for (long long i = 0; i < (N); ++i) {
      P.pop();
      P.push(S[N - i - 1]);
      if (comp(P, O)) {
        O = P;
      }
    }
    for (long long i = 0; i < (N); ++i) {
      U.push_back(O.front());
      O.pop();
    }
    reverse(U.begin(), U.end());
    S = U;
    e *= 2;
    cout << S << endl;
    if (e >= 2 * N) break;
  }
  string U;
  queue<char> O, P;
  for (long long i = 0; i < (N); ++i) {
    O.push(S[i]);
  }
  P = O;
  for (long long i = 0; i < (N); ++i) {
    P.pop();
    P.push(S[N - i - 1]);
    if (comp(P, O)) {
      O = P;
    }
  }
  for (long long i = 0; i < (N); ++i) {
    U.push_back(O.front());
    O.pop();
  }
  S = U;
  return 0;
}
