Maya Calendar

Interview

Time limit1sMemory limit128 MB

Summary
Convert n dates from the Haab calendar to the Tzolkin calendar using modular arithmetic on the day index.
Level

Medium4 of 10

Topics
Math, Implementation, Simulation, Number theory
Solved
No attempts yet

Problem

Professor M. A. Ya has been studying the ancient Maya calendars and needs a program to convert dates from one of them to the other.

The Haab calendar has a 365-day year divided into 19 months. Each of the first 18 months has 20 days, and the days are numbered from 0 to 19. The names of these 18 months, in order, are:

pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu

The 19th and last month is called uayet and has only 5 days, numbered 0 to 4, so a year has 18×20+5=36518 \times 20 + 5 = 365 days. The Maya considered this month unlucky.

The Tzolkin calendar (the holy year) has a 260-day year. Each day is described by a pair: a number together with a day name. There are 20 day names, used in a cycle:

imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau

together with the 13 numbers 11 through 1313, also used in a cycle. The number and the name advance together by one each day, so every day has an unambiguous description. For example, the first days of a Tzolkin year are:

1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, 8 imix, 9 ik, 10 akbal, ...

Years in both calendars are numbered 0,1,2,…0, 1, 2, \ldots, where year 00 marks the beginning of the world. The very first day is therefore:

  • Haab: 0. pop 0
  • Tzolkin: 1 imix 0

Given dates in the Haab calendar, convert each one to the corresponding Tzolkin date.

Input

Each Haab date is written in the format:

NumberOfTheDay. Month Year

The first line of input contains the number of dates nn. Each of the next nn lines contains one date in Haab format. Every year is smaller than 50005000.

Output

For each input date, output the corresponding Tzolkin date in the format:

Number NameOfTheDay Year

The first line of output is the number of dates nn. The next nn lines contain the converted Tzolkin dates, in the same order as the input.

Examples2

  1. Example 1

    Input
    3
    10. zac 0
    0. pop 0
    10. zac 1995
    
    Expected output
    3
    3 chuen 0
    1 imix 0
    9 cimi 2801
    
  2. Example 2

    Input
    1
    0. pop 0
    
    Expected output
    1
    1 imix 0