At a Hong Kong tea house, the bill for a table consists of the tea charge, the dim sum charges, and possibly a $$$10\%$$$ service charge, commonly called plus one.
Each kind of tea has a price per person. Everyone at the same table chooses the same kind of tea, and the tea charge is the number of people multiplied by the price of that tea per person.
Every dim sum dish belongs to exactly one of five price categories. All dishes in the same category have the same price.
| Token | Category |
| SMALL | Small |
| MEDIUM | Medium |
| LARGE | Large |
| SPECIAL | Special |
| DELUXE | Deluxe |
For each table, calculate the bill in the following order:
Given the menu and the orders of several tables, determine the final bill for every table.
The first line contains an integer $$$T$$$ ($$$1\le T\le 1000$$$), the number of kinds of tea.
Each of the next $$$T$$$ lines contains a string $$$t_i$$$ and an integer $$$a_i$$$ ($$$1\le a_i\le 1000$$$), denoting the name and the price per person of tea $$$i$$$.
The next line contains five integers $$$b_{\mathrm{SMALL}}$$$, $$$b_{\mathrm{MEDIUM}}$$$, $$$b_{\mathrm{LARGE}}$$$, $$$b_{\mathrm{SPECIAL}}$$$, and $$$b_{\mathrm{DELUXE}}$$$ ($$$1\le b_{\mathrm{SMALL}},b_{\mathrm{MEDIUM}},b_{\mathrm{LARGE}},b_{\mathrm{SPECIAL}},b_{\mathrm{DELUXE}}\le 1000$$$), the prices of the five categories in exactly this order. These prices are not necessarily increasing.
The next line contains an integer $$$D$$$ ($$$1\le D\le 1000$$$), the number of dim sum dishes.
Each of the next $$$D$$$ lines contains two strings $$$d_i$$$ and $$$c_i$$$, denoting the name and the category of dim sum dish $$$i$$$. $$$c_i$$$ is one of SMALL, MEDIUM, LARGE, SPECIAL, and DELUXE.
The next line contains an integer $$$m$$$ ($$$1\le m\le 1000$$$), the number of tables.
For each table:
It is guaranteed that the sum of $$$k$$$ over all tables does not exceed $$$1000$$$.
Every tea name and dish name consists of $$$1$$$ to $$$20$$$ uppercase English letters, lowercase English letters, or underscores. Names are case-sensitive. Tea names are pairwise distinct, and dish names are pairwise distinct. Every referenced tea and dish is present in the menu.
Print $$$m$$$ lines. The $$$i$$$-th line must contain one integer: the final bill of table $$$i$$$ in Hong Kong dollars.
2Pu_Er 8Jasmine 1020 24 28 32 456Har_Gow DELUXESiu_Mai LARGEChar_Siu_Bao MEDIUMSpring_Roll SMALLEgg_Tart SPECIALCustard_Bun DELUXE33 Pu_Er 4 0Har_Gow 2Siu_Mai 1Har_Gow 1Egg_Tart 22 Jasmine 2 1Char_Siu_Bao 2Spring_Roll 31 Jasmine 3 0Custard_Bun 1Spring_Roll 1Spring_Roll 1
276 128 105
For the first table, the tea charge is $$$3\cdot 8=24$$$. Its dim sum charges total $$$3\cdot45+1\cdot28+2\cdot32=227$$$, so the subtotal is $$$251$$$. The service charge is not waived, and the final bill is $$$276$$$ after rounding.
For the second table, the subtotal is $$$2\cdot10+2\cdot24+3\cdot20=128$$$. The service charge is waived, so the final bill is $$$128$$$.
For the third table, the subtotal is $$$1\cdot10+1\cdot45+2\cdot20=95$$$. The service charge is not waived. The total is exactly halfway between $$$104$$$ and $$$105$$$, so it is rounded upward to $$$105$$$.
Photo by Little Cyan Fish in Hong Kong, July 2026
| Name |
|---|


