#include<bits/stdc++.h>
using namespace std;
char a[13][5]={"tret","jan","feb","mar","apr","may","jun", "jly","aug","sep", "oct","nov","dec"};
char b[12][5]={"tam","hel","maa","huh","tou","kes","hei", "elo","syy","lok", "mer","jou"};
int main(){
int N;
cin>>N;
cin.clear();
cin.ignore();
int count;string s;
for(int i=0;i<N;i++){
getline(cin,s);
if(s[0]>='0'&&s[0]<='9'){
count=0;
int k=1;
int len=s.size()-1;
for(int m=0;m<len;m++){
k=k*10;
}
for(int j=0;s[j]!='\0';j++){
count=count+(s[j]-'0')*k;
k/=10;
}
if(count<13){
cout<<a[count]<<endl;
}
else{
int p=count/13;
int q=count%13;
cout<<b[p-1];
if(q!=0){
cout<<" "<<a[q];
}
cout<<endl;
}
}
else{
int sum=0;
s+=" ";
int pos=s.find_first_of(' ',0);
string sub=s.substr(0,pos);
for(int j=0;j<13;j++)
{
if(sub==b[j])
{
sum=(j+1)*13;
if(s[pos+1]=='\0'){
break;
}
else{
s.erase(0,pos+1);
int pos2=s.find_first_of(' ',0);
string sub2=s.substr(0,pos2);
for(int l=0;l<13;l++){
if(sub2==a[l]){
sum=sum+l;
break;
}
}
//cout<<s;
}
}
if(sub==a[j])
{
sum=sum+j;break;
}
}
cout<<sum<<endl;
}
}
}