#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#define maxn 13
using namespace std;
string one[maxn] = {"tret", "jan", "feb", "mar", "apr", "may",
"jun", "jly", "aug", "sep", "oct", "nov", "dec"},
ten[maxn] = {"tret", "tam", "hel", "maa", "huh", "tou",
"kes", "hei", "elo", "syy", "lok", "mer", "jou"};
int main() {
int N;
cin >> N;
getchar();
while(N--) {
string a, b;
int n;
getline(cin, a);
if (a[0] >= '0' && a[0] <= '9') {
sscanf(a.c_str(), "%d", &n);
if (n >= 13 && n % 13 != 0) {
cout << ten[n / 13] << ' ' << one[n % 13] << endl;
}
else if (n >= 13) cout << ten[n / 13] << endl;
else cout << one[n] << endl;
}
else {
int i = 0;
if (a.size() < 5) {
for (i = 0; i < 13; i++) {
if (one[i] == a) break;
}
n = i;
if (i == 13) {
for (i = 0; i < 13; i++) {
if (ten[i] == a) break;
}
n = i * 13;
}
cout << n << endl;
}
else {
b = a.substr(0, 3);
for (i = 0; i < 13; i++) {
if (ten[i] == b) break;
}
int j = 0;
if (a.size() > 5) {
b = a.substr(4, 3);
for (j = 0; j < 13; j++) {
if (one[j] == b) break;
}
}
cout << i * 13 + j << endl;
}
}
}
return 0;
}