Segmentation

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 MB

Problem

ZOYI 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.

User segments under the RF model. The horizontal axis is Recency and the vertical axis is Frequency.

Here 0<f1<f2<f3<f40 < f_1 < f_2 < f_3 < f_4 and 0<r1<r2<r3<r40 < r_1 < r_2 < r_3 < r_4, and every fif_i and rir_i is an integer.

Each online user gets an rr value and an ff value from the visit log, and falls into one of these 12 segments.

  • New Customer
  • Promising
  • About to Sleep
  • Hibernating
  • Lost
  • Potential Loyalist
  • Need Attention
  • About to Leave
  • Champion
  • Loyal Customer
  • Can't Lose Them
  • None

None means the user has no visit on record. When the point (r,f)(r, f) lies on a boundary between two or more segments in the figure, use the segment of (r0.5,f0.5)(r - 0.5, f - 0.5) instead. For example, (r,f)=(r4,f2)(r, f) = (r_4, f_2) is Hibernating, and (r3,f4)(r_3, f_4) is Loyal Customer. With that rule applied, the segments are the following table.

ff rangerr1r \le r_1r1<rr2r_1 < r \le r_2r2<rr3r_2 < r \le r_3r3<rr4r_3 < r \le r_4r4<rr_4 < r
f4<ff_4 < fChampionLoyal CustomerLoyal CustomerAbout to LeaveCan't Lose Them
f3<ff4f_3 < f \le f_4Loyal CustomerLoyal CustomerLoyal CustomerAbout to LeaveAbout to Leave
f2<ff3f_2 < f \le f_3Potential LoyalistPotential LoyalistNeed AttentionAbout to LeaveAbout to Leave
f1<ff2f_1 < f \le f_2Potential LoyalistPotential LoyalistAbout to SleepHibernatingLost
ff1f \le f_1New CustomerPromisingAbout to SleepLostLost

You want to know who visits the RUN application site, so you install Channel there and analyze it. On this site the rr and ff of a visiting user are defined like this.

  • rr: at the current time tt, the value of tt minus the time of that user's most recent visit
  • ff: the number of visits by that user

Given the visit events on the site, write a program that classifies the customers by the rule above.

Input

The first line contains four natural numbers r1r_1, r2r_2, r3r_3, r4r_4 in that order, separated by spaces.

The second line contains four natural numbers f1f_1, f2f_2, f3f_3, f4f_4 in that order, separated by spaces.

The third line contains the number of events NN.

Each of the next NN lines describes one event in the order the events happened. The event on the ii-th of those lines happens at time ii.

An event is given as AA and BB separated by a space. BB is a user name, made of at most 10 uppercase and lowercase letters with no space. AA 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.

Output

For every event whose AA is 2, print the segment of that customer, one per line. Do not print the quotation marks.

Constraints

  • 1N100,0001 \le N \le 100{,}000
  • 0<r1<r2<r3<r410,0000 < r_1 < r_2 < r_3 < r_4 \le 10{,}000
  • 0<f1<f2<f3<f410,0000 < f_1 < f_2 < f_3 < f_4 \le 10{,}000

Hint

Take the first example. At time 3, Alex has visited once and the most recent visit was at time 2, so f=1f = 1 and r=32=1r = 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=2f = 2 and r=76=1r = 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=3f = 3 and r=85=3r = 8 - 5 = 3. That is Need Attention.