Calendar of Maya

Time limit1sMemory limit128 MB

Problem

The Classical Maya civilization developed in what is today southern Mexico, Guatemala, Belize, and northern Honduras. At its height it built a sophisticated system of timekeeping, used both to record history and for divinatory rituals. The Maya calendar had three components: the Tzolkin, the Haab, and the Long Count.

For divination the Maya used the Tzolkin, formed from 20 day names, each paired with a numeric coefficient from 1 to 13. This gives 260 distinct combinations — the length of the Tzolkin (ritual) year. The 20 day names are:

Imix, Ik, Akbal, Kan, Chikchan, Kimi, Manik, Lamat, Muluk, Ok, Chuen, Eb, Ben, Ix, Men, Kib, Kaban, Etznab, Kawak, Ajaw

Each day both the coefficient and the name advance by one, independently. Starting, for example, at 9 Imix, the sequence runs 9 Imix, 10 Ik, 11 Akbal, 12 Kan, 13 Chikchan, 1 Kimi, 2 Manik, ... (the coefficient wraps from 13 back to 1, the name wraps from Ajaw back to Imix).

The Haab was an astronomical calendar of 365 days, divided into 19 months. Eighteen of the months have 20 days each; the last, Wayeb, has only 5. Within a month the day number runs from 1 to 20 (from 1 to 5 for Wayeb). The 19 month names are:

Pohp, Wo, Sip, Zotz, Sek, Xul, Yaxkin, Mol, Chen, Yax, Sak, Keh, Mak, Kankin, Muan, Pax, Kayab, Kumku, Wayeb

Wayeb, with its 5 days, was considered an unlucky time of the year.

The Tzolkin and the Haab were combined into the Calendar Round, pairing the 260-day Tzolkin cycle with the 365-day Haab cycle. A Calendar Round date looks like 3 Lamat 6 Pax. Because the two cycles share a common factor, not every pairing of a Tzolkin day and a Haab day can occur. A run of consecutive days in the Calendar Round, starting at 3 Lamat 6 Pax, looks like:

3 Lamat 6 Pax, 4 Muluk 7 Pax, 5 Ok 8 Pax, 6 Chuen 9 Pax, 7 Eb 10 Pax, 8 Ben 11 Pax, 9 Ix 12 Pax, 10 Men 13 Pax, 11 Kib 14 Pax, 12 Kaban 15 Pax, 13 Etznab 16 Pax, 1 Kawak 17 Pax, 2 Ajaw 18 Pax, 3 Imix 19 Pax, 4 Ik 20 Pax, 5 Akbal 1 Kayab, 6 Kan 2 Kayab, ...

Finally, the Long Count is an absolute calendar that counts the number of days elapsed since a fixed zero date. A Long Count date is written as five numbers, for example 9.2.3.4.5, read as "9 baktuns, 2 katuns, 3 tuns, 4 winals, 5 kins". The units are:

  • 1 kin = 1 day
  • 1 winal = 20 kins
  • 1 tun = 18 winals = 360 days
  • 1 katun = 20 tuns
  • 1 baktun = 20 katuns

So 9.2.3.4.5 means 9 × 144000 + 2 × 7200 + 3 × 360 + 4 × 20 + 5 days since the zero date. For any Long Count date b.k.t.w.i we have 0 ≤ k < 20, 0 ≤ t < 20, 0 ≤ w < 18, and 0 ≤ i < 20.

Because the Calendar Round repeats, a single Calendar Round date corresponds to many Long Count dates. We restrict our attention to baktuns 8 and 9, which together cover the entire Classic Period. It is known that the Long Count date 8.0.0.0.0 fell on the Calendar Round 9 Ajaw 3 Sip.

For each given Calendar Round date, decide whether it is legal, and if so list every Long Count date in baktuns 8 and 9 that it corresponds to.

Input

The first line contains one integer d, the number of data sets, with 1 ≤ d ≤ 300.

Each of the next d lines contains one Calendar Round date, which may be illegal: the Tzolkin day number, the Tzolkin day name, the Haab day number, and the Haab month name, separated by single spaces.

A date is legal only when the Tzolkin day number is between 1 and 13, the Haab day number is valid for its month (1 to 20 for the 18 regular months, 1 to 5 for Wayeb), and the Tzolkin/Haab pairing is one that can actually occur.

Output

For each data set, output the Long Count dates that correspond to the given Calendar Round date, in ascending order.

First print a line with a single integer n, the number of such dates (0 if the input date is illegal). Then print n lines, each a Long Count date written as exactly five integers — baktuns, katuns, tuns, winals, and kins — separated by single dots.