IntermediateDates & Time25 points

Tenure report and next work anniversary

The HR department of a logistics company in Rotterdam prepares a service-award report. For every employee it needs the exact tenure on a report date and the date of the next work anniversary. Month ends and 29 February make this tricky.

Define add_months(date, k) as the same day number, k months later, but if that month is too short, use its last day (31 Jan plus 1 month is 28 Feb, or 29 Feb in a leap year; 29 Feb plus 12 months in a non-leap year is 28 Feb). Tenure in months is the largest k for which add_months(hire, k) is on or before the report date. The remaining days are the report date minus add_months(hire, k). Years are k // 12 and months are k % 12. The next anniversary is add_months(hire, 12 * (years + 1)).

Task: line 1 is the report date (YYYY-MM-DD), line 2 is n, then n lines name hire_date (names have no spaces, hire dates are never after the report date). For each employee in input order print name: Y years, M months, D days; next anniversary YYYY-MM-DD. Always use the plural words, even for 1.

Sample tests

Input

2026-10-21
3
Aisha 2019-03-15
Pedro 2020-02-29
Chen 2023-10-31

Expected output

Aisha: 7 years, 7 months, 6 days; next anniversary 2027-03-15
Pedro: 6 years, 7 months, 22 days; next anniversary 2027-02-28
Chen: 2 years, 11 months, 21 days; next anniversary 2026-10-31

Input

2025-02-28
2
Leila 2024-02-29
Tomas 2025-01-31

Expected output

Leila: 1 years, 0 months, 0 days; next anniversary 2026-02-28
Tomas: 0 years, 1 months, 0 days; next anniversary 2026-01-31

Your answer is also checked against 3 hidden tests.