#include <iostream>
#include <string>
using namespace std;
string mars0[14] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string mars1[12] = {"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
void MToE(string s){
if (s.length() > 4) {
int sum = 0;
string s0 = s.substr(0, 3);
string s1 = s.substr(4, s.length());
for (int i = 0; i < 12; i++) {
if (s0 == mars1[i]) {
sum = (i + 1) * 13;
break;
}
}
for (int i = 0; i < 13; i++) {
if (s1 == mars0[i]) {
sum += i;
break;
}
}
cout << sum << endl;
}else{
for (int i = 0; i < 13; i++) {
if (mars0[i] == s) {
cout << i << endl;
break;
}else if(mars1[i] == s){
cout << (i + 1) * 13 << endl;
break;
}
}
}
}
void EToM(string s){
int n = stoi(s);
if (n < 13) {
cout << mars0[n] << endl;
}else if(n % 13 == 0){
cout << mars1[n / 13 - 1] << endl;
}else{
cout << mars1[n / 13 - 1] << ' ' << mars0[n % 13] << endl;
}
}
int main(int argc, const char * argv[]) {
int n;
string s;
cin >> n;
getchar();
for (int i = 0; i < n; i++) {
getline(cin, s);
if (s[0] >= '0' && s[0] <= '9') {
EToM(s);
}else{
MToE(s);
}
}
return 0;
}