#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
int main(){
string ones[13]={
"tret", "jan", "feb", "mar", "apr",
"may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string tens[13]={
"", "tam", "hel", "maa", "huh", "tou",
"kes", "hei", "elo", "syy", "lok", "mer", "jou"};
map<string,int> m;
for(int i=0;i<13;i++) m.insert(pair<string,int>(ones[i],i));
for(int i=1;i<13;i++) m.insert(pair<string,int>(tens[i],i*13));
int n;cin>>n;
getchar();
string s;
while(n--){
getline(cin,s);
if(s[0]>='0'&&s[0]<='9'){
int earth = stoi(s);
if(earth/13) cout<<tens[earth/13];
if(earth/13&&earth%13) cout<<" ";
if(earth%13||earth==0) cout<<ones[earth%13];
puts("");
}else{
int earth=0;
if(s.length()>4) earth=m[s.substr(0,3)]+m[s.substr(4,3)];
else earth=m[s];
cout<<earth<<endl;
}
}
}