A restaurant has available ingredients for making pizzas. The ingredients are numbered from to . The menu features different pizzas, each with a specific list of ingredients.
For any given pizza, the restaurant can:
- Add ingredient for a cost of coins;
- Remove ingredient for a cost of coins.
You are given queries. In each query, determine the minimum cost required to modify any existing pizza into a specific target pizza.
Input data
The first line of the input consists of three space-separated integers , , and , denoting the number of ingredients, the number of pizzas, and the number of queries, respectively.
The next lines describe the cost of modifying each ingredient. Each line consists of two space-separated integers and ().
The following lines describe the pizzas on the menu. Each pizza is represented by two consecutive lines in the following form:
- -- the number of ingredients.
- -- the numbers representing each ingredient.
The following lines contain the description of the queries, given in the same format as the description of the pizzas.
Output data
Output lines, the -th of which should contain a single integer denoting the answer to the -th query.
Constraints and clarifications
- .
- .
- for each .
- .
- for each .
- for each .
- All the pizzas are different.
# | Points | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 15 | . |
3 | 25 | . |
4 | 60 | No additional constraints. |
Example
stdin
3 2 3
5 2
3 3
0 10
2
0 1
1
2
1
0
2
0 1
3
0 1 2
stdout
3
0
0
Explanation
In the sample case, there are types of ingredients. The cost of adding each of them is , , and coins, and the cost of removing each of them is , , and coins, respectively.
There are different pizzas on the menu. The first one has two ingredients: ingredient and ingredient ; and the second pizza has only one ingredient: ingredient .
You are asked to create pizzas:
- In the first query, you have to pay coins to transform one of the two pizzas at the restaurant into a pizza with only ingredient .
- In the second query, the specified pizza already exists, so you don't have to pay anything.
- In the third query, you can pay coins and add the third ingredient to the first pizza, obtaining the requested pizza.