The New World is a chaotic sea, but even the most notorious pirate crews have a rhythm to their madness. "Big News" Morgans, president of the World Economy News Paper, has discovered that every pirate crew follows a bizarre, endlessly repeating cycle of daily activities. He is utilizing this predictability to track their movements, anticipate clashes, and write his next front-page headline.
There are $$$K$$$ pirate crews currently being tracked. Each crew $$$i$$$ enters the New World on a specific starting date and follows an infinitely repeating activity cycle represented by a string $$$P_i$$$. The string consists of the characters S (Sailing), F (Fighting), P (Partying), and D (Docked).
For example, if a crew's pattern is SFFD, they will spend their first active day sailing, the next two days fighting, the fourth day docked, and on the fifth day, the cycle restarts with sailing. A crew is considered strictly inactive on any date prior to their starting date.
Morgans has a series of $$$Q$$$ queries to track the fleets. You must process three types of queries:
The first line contains a single integer $$$K$$$ ($$$1 \le K \le 50$$$) — the number of pirate crews.
The following $$$K$$$ lines describe the crews. The $$$i$$$-th line contains three space-separated strings:
The next line contains a single integer $$$Q$$$ ($$$1 \le Q \le 5000$$$) — the number of queries.
The following $$$Q$$$ lines each contain a space-separated query in one of the following formats:
All dates in the input are guaranteed to be valid and fall within the range 01/01/2000 to 31/12/2050 inclusive. Additionally, for Type 3 queries, it is guaranteed that the entire $$$69$$$-day window (the given date and the $$$68$$$ days following it) will strictly fall on or before 31/12/2050.
For each query, output the answer on a new line:
4STRAWHAT 28/02/2024 SFFHEART 01/03/2024 FDDKID 01/03/2024 SFPBUGGY 01/01/2024 P61 01/03/2024 F1 29/02/2024 D2 STRAWHAT 02 20242 HEART 02 20243 STRAWHAT HEART 28/02/20243 BUGGY KID 01/01/2024
HEART STRAWHAT NONE 1 1 0 0 0 0 01/03/2024 PEACE
Explanation of the test case
The year 2024 is a leap year, meaning February has 29 days.
| Название |
|---|


