N,K=map(int, input().split()) S=list(input()) n=N-K+1 for i in range(n): p=S[:i] d=S[i:i+K][::-1] a=S[i+K:] S=p+d+a print(*(p+d+a),sep='')