NASA has secretly built a time machine that can travel into the past, and its first mission is to explore Maya culture. Researchers gathered important dates from Maya monuments that are worth investigating, but the time machine only accepts Gregorian dates as input, so the Maya dates must first be converted.
Given either a Gregorian date or a Maya Long Count, write a program that prints the corresponding Gregorian date, Maya Long Count, and Maya ritual date.
Day zero of the Maya calendar is 13 August 3114 BC. Every date is counted as the number of days elapsed since that day. One day is a K’in; 20 K’in make a Winal; 18 Winal make a Tun; 20 Tun make a K’atun; and 20 K’atun make a Bak’tun. A Long Count is written as five numbers Bak’tun.K’atun.Tun.Winal.K’in. For example, 12.4.9.13.3 means that 12 Bak’tun, 4 K’atun, 9 Tun, 13 Winal, and 3 K’in (days) have passed since 13 August 3114 BC.
A ritual date combines two cycles that turn independently.
Haab (solar calendar). The solar year has 365 days with no leap days. It is divided into 18 months of 20 days plus one month of 5 days. The month names, in order, are Pop, Wo, Sip, Sotz’, Tzek, Xul, Yaxk’in, Mol, Ch’en, Yax, Sak, Keh, Mak, K’ank’in, Muwan, Pax, K’ayab, Kumk’u, Wayeb. The days of a month are numbered 1 to 19 (or 1 to 4 for Wayeb); the last day of a month is written as day 0 of the following month. Thus the last day of the first month is written 0 Wo rather than 20 Pop, and the last day of the five-day month Wayeb is written 0 Pop rather than 5 Wayeb.
Tzolk’in (ritual calendar). Every day also carries a number from 1 to 13 together with one of 20 names: Imix, Ik’, Ak’bal, K’an, Chikchan, Kimi, Manik’, Lamat, Muluk, Ok, Chuwen, Eb, Ben, Ix, Men, Kib, Kaban, Etz’nab, Kawak, Ahaw. Both the number and the name advance every day, so the sequence runs 1 Imix, 2 Ik’, 3 Ak’bal, …, 13 Ben, 1 Ix, 2 Men, …. The same number-and-name pair recurs only after 260 days (the ritual year).
The two parts are written together, for example 2 Kimi 10 Yax, where 2 Kimi is the Tzolk’in part and 10 Yax is the Haab part. The ritual date of 13 August 3114 BC is 4 Ahaw 8 Kumk’u.
Our calendar uses leap days: a leap day is added every 4 years, except every 100 years, but again every 400 years. There is no year 0, so 31 December 1 BC is immediately followed by 1 January AD 1. Consequently the last leap year before Christ is 1 BC (by the 400-year rule), and the next leap year after it is AD 4.
The first line contains the number of scenarios.
Each scenario is a single line containing either a Maya Long Count or a Gregorian date:
12.19.10.6.14.d, m, y separated by slashes with 1≤d≤31, 1≤m≤12, and y>0. The values may or may not be zero-padded, but d and m never exceed two digits and y never exceeds four digits. The date is always followed by a single space and either BC or AD.No date precedes 13 August 3114 BC, and none follows 13.0.0.0.0, the last day of the Maya Long Count. Every given date is valid in its calendar.
For each scenario, first print a line Scenario #i:, where i is the scenario number starting at 1. Then, regardless of the input format, print exactly three lines describing the same date:
Separate consecutive scenarios with a blank line.

Figure 1: Maya ritual dates.