Water Gate Management#3095

Water Gate Management

1 second
64 megabytes
Medium

A dam has water gates to release water when needed. Each water gate has its own flow rate and damage cost, which is determined by the number of people and areas estimated to be affected downstream when it is open.

Suppose water gate G_i has a flow rate of F_i m^3/hour and a damage cost of C_i. In a certain situation, the dam must release at least m^3 of water within hours. Your task is to manage the opening times of the gates so that at least the required water volume is released within the time limit, while minimizing the total damage cost.

For example, consider a dam with water gates. Their properties are listed in a table (not shown here).

Case 1: You must release million m^3 of water in hours. The minimum cost is , which can be achieved by opening gate G_1 for hours.

Case 2: You must release million m^3 of water in hours. The minimum cost is , which can be achieved, for example, by opening gates G_2 and G_3 (G_2 open for hours and G_3 for hours).

Note that each water gate is independent and can be open only for a whole number of hours (no fractional hours).

Input

The first line contains an integer (1 \leq n \leq 20) — the number of water gates. The next lines each contain two integers: F_i and C_i — the flow rate (m^3/hour) and the damage cost for gate G_i, respectively. The next line contains the integer (1 \leq m \leq 50) — the number of test cases. The following lines each contain two integers: and — the volume (m^3) of water to release and the time limit in hours.

1 \leq F_i, V, C_i \leq 10^9, 1 \leq T \leq 1000

Output

For each test case, print the minimum cost in the exact format shown in the sample output. If it is impossible to release m^3 of water in hours from the dam, print "IMPOSSIBLE" (without quotation marks).

Examples

Example 1

Loading
Loading