#include <bits/stdc++.h>
using namespace std;
int main(){
int H, L, move=0, skip=0;
string s;
cin>>H>>L;
cin.ignore();
cin>>s;
int size = H*L;//size of the grid
vector <char> vec(size);//declaring the vector as the size of the grid
for(int i=0; i+skip<s.length(); i++){//looping to input the chars into the vector
//T"h"eQuic"k"BrownFoxJumpsOverT"h"eLazyDog
//eQuick
cout<<move<<"\n";
if(s[i]=='h'){
if(i+move-skip+1%L!=1 || i+move-skip+1%L!=0){
move--;
skip++;
vec[i+move]=s[i+skip];
}
else{
move+=L-1;
skip++;
vec[i+move]=s[i+skip];
}
}
else if(s[i]=='l'){
if(i+move-skip+1%L!=1 || i+move-skip+1%L!=0){
move++;
skip++;
vec[i+move]=s[i+skip];
}
else{
move-=L-1;
skip++;
vec[i+move]=s[i+skip];
}
}
else if(s[i]=='j'){
if(i+move-skip+1<L){
move+=5;
skip++;
vec[i+move]=s[i+skip];
}
else{
move-=(size)-(i+1);
skip++;
vec[i+move]=s[i+skip];
}
}
else if(s[i]=='k'){
if(i+1+move-skip>size-L){
move-=5;
skip++;
vec[i+move]=s[i+skip];
}
else{
move+=(size)-(i+1);
skip++;
vec[i+move]=s[i+skip];
}
}
else{
vec[i+move]=s[i+skip];
}
}
for(int i=0; i<vec.size(); i++){
cout<<vec[i];
if(i+1==L){
cout<<"\n";
}
}
if(vec.size()<size){
for(int i=0; i<size-vec.size(); i++){
cout<<".";
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpewogIGludCBILCBMLCBtb3ZlPTAsIHNraXA9MDsKICBzdHJpbmcgczsKICBjaW4+Pkg+Pkw7CiAgY2luLmlnbm9yZSgpOwogIGNpbj4+czsKICBpbnQgc2l6ZSA9IEgqTDsvL3NpemUgb2YgdGhlIGdyaWQKICB2ZWN0b3IgPGNoYXI+IHZlYyhzaXplKTsvL2RlY2xhcmluZyB0aGUgdmVjdG9yIGFzIHRoZSBzaXplIG9mIHRoZSBncmlkCiAgZm9yKGludCBpPTA7IGkrc2tpcDxzLmxlbmd0aCgpOyBpKyspey8vbG9vcGluZyB0byBpbnB1dCB0aGUgY2hhcnMgaW50byB0aGUgdmVjdG9yCi8vVCJoImVRdWljImsiQnJvd25Gb3hKdW1wc092ZXJUImgiZUxhenlEb2cKLy9lUXVpY2sgIAogICAgY291dDw8bW92ZTw8IlxuIjsKICAgIGlmKHNbaV09PSdoJyl7CiAgICAgIGlmKGkrbW92ZS1za2lwKzElTCE9MSB8fCBpK21vdmUtc2tpcCsxJUwhPTApewogICAgICAgIG1vdmUtLTsKICAgICAgICBza2lwKys7CiAgICAgICAgdmVjW2krbW92ZV09c1tpK3NraXBdOwogICAgICB9CiAgICAgIGVsc2V7CiAgICAgICAgbW92ZSs9TC0xOwogICAgICAgIHNraXArKzsKICAgICAgICB2ZWNbaSttb3ZlXT1zW2krc2tpcF07CiAgICAgIH0KICAgIH0KICAgIGVsc2UgaWYoc1tpXT09J2wnKXsKICAgICAgaWYoaSttb3ZlLXNraXArMSVMIT0xIHx8IGkrbW92ZS1za2lwKzElTCE9MCl7CiAgICAgICAgbW92ZSsrOwogICAgICAgIHNraXArKzsKICAgICAgICB2ZWNbaSttb3ZlXT1zW2krc2tpcF07CiAgICAgIH0KICAgICAgZWxzZXsKICAgICAgICBtb3ZlLT1MLTE7CiAgICAgICAgc2tpcCsrOwogICAgICAgIHZlY1tpK21vdmVdPXNbaStza2lwXTsKICAgICAgfQogICAgfQogICAgZWxzZSBpZihzW2ldPT0naicpewogICAgICBpZihpK21vdmUtc2tpcCsxPEwpewogICAgICAgIG1vdmUrPTU7CiAgICAgICAgc2tpcCsrOwogICAgICAgIHZlY1tpK21vdmVdPXNbaStza2lwXTsKICAgICAgfQogICAgICBlbHNlewogICAgICAgIG1vdmUtPShzaXplKS0oaSsxKTsKICAgICAgICBza2lwKys7CiAgICAgICAgdmVjW2krbW92ZV09c1tpK3NraXBdOwogICAgICB9CiAgICB9CiAgICBlbHNlIGlmKHNbaV09PSdrJyl7CiAgICAgIGlmKGkrMSttb3ZlLXNraXA+c2l6ZS1MKXsKICAgICAgICBtb3ZlLT01OwogICAgICAgIHNraXArKzsKICAgICAgICB2ZWNbaSttb3ZlXT1zW2krc2tpcF07CiAgICAgIH0KICAgICAgZWxzZXsKICAgICAgICBtb3ZlKz0oc2l6ZSktKGkrMSk7CiAgICAgICAgc2tpcCsrOwogICAgICAgIHZlY1tpK21vdmVdPXNbaStza2lwXTsKICAgICAgfQogICAgfQogICAgZWxzZXsKICAgICAgdmVjW2krbW92ZV09c1tpK3NraXBdOwogICAgfQogIH0KICBmb3IoaW50IGk9MDsgaTx2ZWMuc2l6ZSgpOyBpKyspewogICAgY291dDw8dmVjW2ldOwogICAgaWYoaSsxPT1MKXsKICAgICAgY291dDw8IlxuIjsKICAgIH0KICB9CiAgaWYodmVjLnNpemUoKTxzaXplKXsKICAgIGZvcihpbnQgaT0wOyBpPHNpemUtdmVjLnNpemUoKTsgaSsrKXsKICAgICAgY291dDw8Ii4iOwogICAgfQogIH0KfQo=