#include <iostream>
#include <string.h>
using namespace std;
char ch[2][13][5] =
{
"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec",
"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"
};
int getindex(int index, char s[])
{
int i;
for(i = 0; i < 13; i++)
{
if(strcmp(ch[index][i], s) == 0)
{
return i;
}
}
return -1;
}
int main()
{
int n;
scanf("%d", &n);
getchar();
int i, len, num, j, k, low, high, index;
char s[20], curs[5];
for(i = 1; i <= n; i++)
{
gets(s);
len = strlen(s);
if(s[0] >= '0' && s[0] <= '9')
{
num = 0;
for(j = 0; j < len; j++)
{
num = num * 10 + s[j] - '0';
}
if(num < 13)
{
printf("%s\n", ch[0][num]);
}
else
{
low = num % 13;
high = num / 13;
printf("%s", ch[1][high]);
if(low > 0)
{
printf(" %s\n", ch[0][low]);
}
else
{
printf("\n");
}
}
}
else
{
if(len <= 4)
{
for(j = 0; j <= 1; j++)
{
index = getindex(j, s);
if(index != -1)
{
break;
}
}
if(j == 0)
{
num = index;
}
else
{
num = 13 * index;
}
}
else
{
for(j = 0; s[j] != ' '; j++)
{
curs[j] = s[j];
}
curs[j] = '\0';
num = getindex(1, curs) * 13;
for(k = j + 1, j = 0; k < len; k++, j++)
{
curs[j] = s[k];
}
curs[j] = '\0';
num += getindex(0, curs);
}
printf("%d\n", num);
}
}
system("pause");
return 0;
}