#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<sstream>
#include<string>
using namespace std;
int n;
string last[13]={"","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"},
up[13]={"","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
unordered_map<string,int> map,mmd;
void cale(string a)
{
int t=stoi(a);
string res=last[t%13];
t/=13;
while(t)
{
res.insert(0,up[t%13]+" ");
t/=13;
}
if(res=="") res="tret";
cout<< res<<endl;
}
void calm(string a)
{
stringstream s(a);
string t;
int res;
bool b=false;
while(s>>t)
{
if(b)
res=res*13+map[t];
else
{
res=mmd[t];
}
b=true;
}
if(res==0) res=map[t];
else if(res<13) res*=13;
cout<<res<<endl;
}
int main()
{
for(int i=0;i<13;i++)
{
map[last[i]]=i;
mmd[up[i]]=i;
}
cin>>n;
cin.ignore();
for(int i=0;i<n;i++)
{
string t;
getline(cin,t);
if(isdigit(t[0]))
cale(t);
else
{
calm(t);
}
}
return 0;
}