Abusing 1Fit limits#9418

Abusing 1Fit limits

1 Sekunde
128 Megabyte
Leicht

1Fit - is a subscription-based startup, within 1Fit you can visit multiple gyms without buying separate subscriptions.

In 1Fit we have **n** fitnesses, **m** trainings and **k** sport types. All entities numbered consecutively starting from **1**. Each training has _fitnessID_ and _sporttypeID_ specified.

There are **r** rules, each rule describes the book limit per user. In each rule specified fitness, list of sport types and limit, **limit** = **-1** stands for an unlimited book, e.g. if _fitnessID_ = **3** and _sporttypes_ = [**1**, **2**, **6**] and **limit** = **7** means that the number of bookings with 3rd fitness and sporttype equals to **1** or **2** or **6** cannot exceed **7**. One training cannot be booked multiple times. It's guaranteed that each pair _fitnessID_ and _sporttypeID_ can appear in at most one rule as well.

Aisultan recently bought a 1Fit subscription to get more healthy. He sent **q** consecutive book queries. For each query server must return either '**yes**' or '**no**', is training booked successfully or the booking was incorrect. Write a program to process all Aisultan's queries.

Eingabe

The first line contains three positive integer numbers **n**, **m** and **k** (**1** ≤ **n**, **m**, **k** ≤ **100**) - the number of fitnesses, trainings and sport types, respectively. Each of the next **m** lines contains two integers _fitnessID_, _sporttypeID_ (**1** ≤ _fitnessID_ ≤ **n**, **1** ≤ _sporttypeID_ ≤ **k**) - description of trainings: fitness ID and sport type ID of training. Next line contains one positive integer **r** (**1** ≤ **r** ≤ **100**) - number of rules. Each of the next **r** lines contains the first ID of fitness, following by the number of sport types in this rule and list of sport type ids and limit at the end. The next line contains one positive number **q** (**1** ≤ **q** ≤ **100**) - the number of Aisultan's queries. Each of the next **q** lines contains one integer - description of query: ID of training.

Ausgabe

For each query output either '**yes**' or '**no**'.

Beispiele

Beispiel 1

Loading
Loading

Notiz

In the example, we have **3** fitnesses, **8** trainings and **3** sport types. Training lists are: (**1**, **1**), (**1**, **2**), ..., i.e. training number **1** in fitness with ID **1** with sport type ID **1**, training number **2** in fitness with ID **1** with sport type ID **2**, ...

Have **4** rules:

1. _fitnessID_ = **1**, _sporttypeIDs_ = [**2**] **limit** = **-1** - Aisultan can book trainings with _fitnessID_ = **1** and _sporttypeID_ = **2** unlimited times;

2. _fitnessID_ = **2**, _sporttypeIDs_ = [**2**, **3**] **limit** = **2** - Aisultan can book trainings with _fitnessID_ = **2** and _sporttypeID_ = **2** or _fitnessID_ = **2** and _sporttypeID_ = **3** no more than twice in total;

3. _fitnessID_ = **3**, _sporttypeIDs_ = [**1**] **limit** = **-1** - Aisultan can book trainings with _fitnessID_ = **3** and _sporttypeID_ = **1** an unlimited number of times;

4. _fitnessID_ = **1**, _sporttypeIDs_ = [**1**] **limit** = **1** - Aisultan can book trainings with _fitnessID_ = **1** and _sporttypeID_ = **1** no more than once;

The first three queries Aisultan can book successfully. **4**-th query will be '**no**' because Aisultan cannot book **2**nd training twice. Also **7**th query's response is '**no**', because Aisultan cannot book training with _fitnessID_ = **1** and _sporttypeID_ = **1** twice.