N, K = map(int, input().split()) S = list(input()) print(S) for i in range(N - K + 1): S[i:i + K] = reversed(S[i: i + K]) print(''.join(S))