Air Old Zeeland

No attempts yetTime limit1sMemory limit128 MB

Problem

Air Old Zeeland — known informally as Air OZ — has begun letting customers redeem their loyalty points for products. Because the idea is new, Air OZ is testing the market with a small, curated set of products. The suppliers, however, often struggle to keep up with demand, so Air OZ decided to record, for each product, both its listed price (in loyalty points) and the number of days a customer must wait for it to be shipped. This lets them gauge how many discontented customers they have.

Input

The input consists of several scenarios.

The first line of each scenario contains an integer $N$ ($0 < N \le 50$), the number of products on offer. A scenario whose first line is $0$ marks the end of the input and must not be processed.

The next $N$ lines each describe one product. A line contains the product name, the number of loyalty points needed to redeem it, and the number of days to wait for shipping, separated by single spaces. A product name is at most 20 characters long and contains no spaces. No product costs more than 1000 loyalty points, and no product is delayed by more than 100 days.

The product lines are followed by a line containing $C$ ($0 < C \le 500$), the number of customers in this scenario. Each customer is described by a line containing the customer number, the number of products they wish to buy $P$, and the maximum number of days $M$ they are willing to wait ($0 < P \le N$, $0 < M < 100$), separated by single spaces. That line is followed by $P$ lines, each naming one product the customer wants to order.

Output

For each customer, print one line with the customer number and the total value of the products they successfully purchased, separated by a single space. A product is purchased only if its shipping delay is at most the customer's maximum wait $M$ days; otherwise it is not purchased and the customer becomes discontented. If the customer failed to obtain at least one product they wanted, append a single space followed by an asterisk (*). Do not print a trailing space when there is no asterisk.

After listing all customers of a scenario, print a final line consisting of the text Number of discontented customers is:, a single space, and the number of discontented customers in that scenario (that is, the number of asterisks printed).

Hint

In the example, both products customer 1001 wants can be shipped within their acceptable time frame, so both are purchased.

Customer 1860's requested product cannot be shipped in time, so nothing is bought and the customer is discontented.

Customer 1025 can receive one of their two products in time (the iPodNano, worth 255) but not the other (the perfume), so the total is 255 and an asterisk is printed.

This leaves 2 customers who could not complete their purchases.