Track visits per user over time and answer queries by mapping each user's recency and frequency to one of 12 RF segments.
Medium4Hash mapImplementationSimulationArrayInterviewNo attempts yetTime limit1sMemory limit1024 MBZOYI builds a tool called Channel that lets a site talk with the online users who visit it. To sort the users of Channel, ZOYI recently adopted an RF (Recency / Frequency) model and decided to group users by the calculation below.

Here 0<f1<f2<f3<f4 and 0<r1<r2<r3<r4, and every fi and ri is an integer.
Each online user gets an r value and an f value from the visit log, and falls into one of these 12 segments.
New CustomerPromisingAbout to SleepHibernatingLostPotential LoyalistNeed AttentionAbout to LeaveChampionLoyal CustomerCan't Lose ThemNoneNone means the user has no visit on record. When the point (r,f) lies on a boundary between two or more segments in the figure, use the segment of (r−0.5,f−0.5) instead. For example, (r,f)=(r4,f2) is Hibernating, and (r3,f4) is Loyal Customer. With that rule applied, the segments are the following table.
| f range | r≤r1 | r1<r≤r2 | r2<r≤r3 | r3<r≤r4 | r4<r |
|---|---|---|---|---|---|
| f4<f | Champion | Loyal Customer | Loyal Customer | About to Leave | Can't Lose Them |
| f3<f≤f4 | Loyal Customer | Loyal Customer | Loyal Customer | About to Leave | About to Leave |
| f2<f≤f3 | Potential Loyalist | Potential Loyalist | Need Attention | About to Leave | About to Leave |
| f1<f≤f2 | Potential Loyalist | Potential Loyalist | About to Sleep | Hibernating | Lost |
| f≤f1 | New Customer | Promising | About to Sleep | Lost | Lost |
You want to know who visits the RUN application site, so you install Channel there and analyze it. On this site the r and f of a visiting user are defined like this.
Given the visit events on the site, write a program that classifies the customers by the rule above.
The first line contains four natural numbers r1, r2, r3, r4 in that order, separated by spaces.
The second line contains four natural numbers f1, f2, f3, f4 in that order, separated by spaces.
The third line contains the number of events N.
Each of the next N lines describes one event in the order the events happened. The event on the i-th of those lines happens at time i.
An event is given as A and B separated by a space. B is a user name, made of at most 10 uppercase and lowercase letters with no space. A is either 1 or 2. A 1 means the user visited the site, and a 2 means you must print which segment that user is in at that moment.
For every event whose A is 2, print the segment of that customer, one per line. Do not print the quotation marks.
Take the first example. At time 3, Alex has visited once and the most recent visit was at time 2, so f=1 and r=3−2=1. That is New Customer.
At time 7, Alex has visited twice and the most recent visit was at time 6, so f=2 and r=7−6=1. That is Potential Loyalist.
At time 8, RUN has visited three times and the most recent visit was at time 5, so f=3 and r=8−5=3. That is Need Attention.