#include<bits/stdc++.h>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)
#define MOD 1000000007
#define MX 100010
string reverse (string s)
{
string result="";
int sl=s.length();
for (int i=0; i<sl; i++)
result = s[i] + result ;
return result;
}
int main()
{
int tc,kk=1, n, r, sl;
string s;
while(cin>>r && r)
{
cin>>n;
getline(cin,s);
sl=s.length();
int pos=0;
while(s[pos]==' ') pos++;
string s1="";
string s2="";
if(s[pos]=='"')
{
pos++;
while(s[pos]!='"')
{
s1+=s[pos];
pos++;
}
}
else
{
while(s[pos]!=' ')
{
s1+=s[pos];
pos++;
}
}
pos=sl-1;
while(s[pos]==' ') pos--;
if(s[pos]=='"')
{
pos--;
while(s[pos]!='"')
{
s2+=s[pos];
pos--;
}
}
else
{
while(s[pos]!=' ')
{
s2+=s[pos];
pos--;
}
}
s2=reverse(s2);
for(int i=0;i<s1.length();i++)
if(s1[i]>='A' && s1[i]<='Z')
s1[i]=tolower(s1[i]);
for(int i=0;i<s2.length();i++)
if(s2[i]>='A' && s2[i]<='Z')
s2[i]=tolower(s2[i]);
cout<<kk++<<". ";
if(((r-1)/n)%2==0)
cout<<s1<<endl;
else cout<<s2<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgU0VUKGEpIG1lbXNldChhLC0xLHNpemVvZihhKSkKI2RlZmluZSBDTFIoYSkgbWVtc2V0KGEsMCxzaXplb2YoYSkpCiNkZWZpbmUgUEkgYWNvcygtMS4wKQoKI2RlZmluZSBNT0QgMTAwMDAwMDAwNwojZGVmaW5lIE1YIDEwMDAxMAoKc3RyaW5nIHJldmVyc2UgKHN0cmluZyBzKQp7CiAgICBzdHJpbmcgcmVzdWx0PSIiOwogICAgaW50IHNsPXMubGVuZ3RoKCk7CiAgICBmb3IgKGludCBpPTA7IGk8c2w7IGkrKykKICAgICAgICByZXN1bHQgPSBzW2ldICsgcmVzdWx0IDsKcmV0dXJuIHJlc3VsdDsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgdGMsa2s9MSwgbiwgciwgc2w7CiAgICBzdHJpbmcgczsKCiAgICB3aGlsZShjaW4+PnIgJiYgcikKICAgIHsKICAgICAgICBjaW4+Pm47CiAgICAgICAgZ2V0bGluZShjaW4scyk7CiAgICAgICAgc2w9cy5sZW5ndGgoKTsKICAgICAgICBpbnQgcG9zPTA7CiAgICAgICAgd2hpbGUoc1twb3NdPT0nICcpIHBvcysrOwogICAgICAgIAogICAgICAgIHN0cmluZyBzMT0iIjsKICAgICAgICBzdHJpbmcgczI9IiI7CiAgICAgICAgaWYoc1twb3NdPT0nIicpCiAgICAgICAgewogICAgICAgICAgICBwb3MrKzsKICAgICAgICAgICAgd2hpbGUoc1twb3NdIT0nIicpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHMxKz1zW3Bvc107CiAgICAgICAgICAgICAgICBwb3MrKzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICB3aGlsZShzW3Bvc10hPScgJykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgczErPXNbcG9zXTsKICAgICAgICAgICAgICAgIHBvcysrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHBvcz1zbC0xOwogICAgICAgIHdoaWxlKHNbcG9zXT09JyAnKSBwb3MtLTsKICAgICAgICBpZihzW3Bvc109PSciJykKICAgICAgICB7CiAgICAgICAgICAgIHBvcy0tOwogICAgICAgICAgICB3aGlsZShzW3Bvc10hPSciJykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgczIrPXNbcG9zXTsKICAgICAgICAgICAgICAgIHBvcy0tOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHdoaWxlKHNbcG9zXSE9JyAnKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzMis9c1twb3NdOwogICAgICAgICAgICAgICAgcG9zLS07CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgczI9cmV2ZXJzZShzMik7CiAgICAgIAogICAgICAgIGZvcihpbnQgaT0wO2k8czEubGVuZ3RoKCk7aSsrKQogICAgICAgICAgICBpZihzMVtpXT49J0EnICYmIHMxW2ldPD0nWicpCiAgICAgICAgICAgICAgICBzMVtpXT10b2xvd2VyKHMxW2ldKTsKICAgICAgICBmb3IoaW50IGk9MDtpPHMyLmxlbmd0aCgpO2krKykKICAgICAgICAgICAgaWYoczJbaV0+PSdBJyAmJiBzMltpXTw9J1onKQogICAgICAgICAgICAgICAgczJbaV09dG9sb3dlcihzMltpXSk7CiAgICAgICAgY291dDw8a2srKzw8Ii4gIjsKICAgICAgICBpZigoKHItMSkvbiklMj09MCkKICAgICAgICAgICAgY291dDw8czE8PGVuZGw7CiAgICAgICAgZWxzZSBjb3V0PDxzMjw8ZW5kbDsKCiAgICB9CiAgICByZXR1cm4gMDsKfQ==