#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char mp1[20][10]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"};
char mp2[20][10]={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
signed main()
{
int T; scanf("%d", &T); printf("%d\n", T);
while (T --)
{
int ans = 0, sum = 0, day, year, num; char mon[10];
scanf("%d. %s %d", &day, mon, &year);
for (int i = 0; i < 20; i ++)
{
if (strcmp(mp1[i], mon) == 0)
{
ans = year * 365 + day + i * 20; break;
}
}
ans ++;
year = ans / 260;
num = ans % 260;
if (num == 0){year --, num += 260;}
day = num % 13;
if (day == 0) day = 13;
int res = num % 20;
if (res == 0) res = 20;
printf("%d %s %d\n", day, mp2[res - 1], year);
}
return 0;
}